github.com/kotalco/kotal@v0.3.0/controllers/filecoin/config.go (about) 1 package controllers 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/BurntSushi/toml" 8 filecoinv1alpha1 "github.com/kotalco/kotal/apis/filecoin/v1alpha1" 9 "github.com/kotalco/kotal/controllers/shared" 10 ) 11 12 type API struct { 13 ListenAddress string 14 RequestTimeout string 15 } 16 17 type Backup struct { 18 DisableMetadataLog bool 19 } 20 21 type LibP2P struct { 22 ListenAddresses []string 23 } 24 25 type Client struct { 26 UseIpfs bool 27 IpfsOnlineMode bool 28 IpfsMAddr string 29 IpfsUseForRetrieval bool 30 } 31 32 type Chainstore struct { 33 EnableSplitstore bool 34 } 35 36 type Config struct { 37 API *API `toml:"API,omitempty"` 38 Backup Backup 39 LibP2P LibP2P `toml:"Libp2p"` 40 Client *Client 41 Chainstore Chainstore 42 } 43 44 // ConfigFromSpec generates config.toml file from node spec 45 func ConfigFromSpec(node *filecoinv1alpha1.Node) (config string, err error) { 46 c := &Config{} 47 48 if node.Spec.API { 49 c.API = &API{ 50 ListenAddress: fmt.Sprintf("/ip4/%s/tcp/%d/http", shared.Host(node.Spec.API), node.Spec.APIPort), 51 } 52 c.API.RequestTimeout = fmt.Sprintf("%ds", node.Spec.APIRequestTimeout) 53 } 54 55 c.Backup.DisableMetadataLog = node.Spec.DisableMetadataLog 56 57 c.LibP2P.ListenAddresses = []string{fmt.Sprintf("/ip4/%s/tcp/%d", shared.Host(true), node.Spec.P2PPort)} 58 59 if node.Spec.IPFSPeerEndpoint != "" { 60 c.Client = &Client{ 61 UseIpfs: true, 62 IpfsMAddr: node.Spec.IPFSPeerEndpoint, 63 IpfsOnlineMode: node.Spec.IPFSOnlineMode, 64 IpfsUseForRetrieval: node.Spec.IPFSForRetrieval, 65 } 66 } 67 68 c.Chainstore.EnableSplitstore = true 69 70 var buff bytes.Buffer 71 enc := toml.NewEncoder(&buff) 72 err = enc.Encode(c) 73 if err != nil { 74 return 75 } 76 77 config = buff.String() 78 79 return 80 }