github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/p2p/network.go (about) 1 package p2p 2 3 import ( 4 "errors" 5 "time" 6 7 "github.com/libp2p/go-libp2p/core/peer" 8 ) 9 10 // NOTE: Every time we add a new long-running network, it has to be added here. 11 const ( 12 // DefaultNetwork is the default network of the current build. 13 DefaultNetwork = Mainnet 14 // Arabica testnet. See: celestiaorg/networks. 15 Arabica Network = "arabica-11" 16 // Mocha testnet. See: celestiaorg/networks. 17 Mocha Network = "mocha-4" 18 // Private can be used to set up any private network, including local testing setups. 19 Private Network = "private" 20 // Celestia mainnet. See: celestiaorg/networks. 21 Mainnet Network = "celestia" 22 // BlockTime is a network block time. 23 // TODO @renaynay @Wondertan (#790) 24 BlockTime = time.Second * 10 25 ) 26 27 // Network is a type definition for DA network run by Celestia Node. 28 type Network string 29 30 // Bootstrappers is a type definition for nodes that will be used as bootstrappers. 31 type Bootstrappers []peer.AddrInfo 32 33 // ErrInvalidNetwork is thrown when unknown network is used. 34 var ErrInvalidNetwork = errors.New("params: invalid network") 35 36 // Validate the network. 37 func (n Network) Validate() (Network, error) { 38 // return actual network if alias was provided 39 if net, ok := networkAliases[string(n)]; ok { 40 return net, nil 41 } 42 if _, ok := networksList[n]; !ok { 43 return "", ErrInvalidNetwork 44 } 45 return n, nil 46 } 47 48 // String returns string representation of the Network. 49 func (n Network) String() string { 50 return string(n) 51 } 52 53 // networksList is a strict list of all known long-standing networks. 54 var networksList = map[Network]struct{}{ 55 Mainnet: {}, 56 Arabica: {}, 57 Mocha: {}, 58 Private: {}, 59 } 60 61 // networkAliases is a strict list of all known long-standing networks 62 // mapped from the string representation of their *alias* (rather than 63 // their actual value) to the Network. 64 var networkAliases = map[string]Network{ 65 "mainnet": Mainnet, 66 "arabica": Arabica, 67 "mocha": Mocha, 68 "private": Private, 69 } 70 71 // listProvidedNetworks provides a string listing all known long-standing networks for things like 72 // command hints. 73 func listProvidedNetworks() string { 74 var networks string 75 for net := range networksList { 76 // "private" network isn't really a choosable option, so skip 77 if net != Private { 78 networks += string(net) + ", " 79 } 80 } 81 // chop off trailing ", " 82 return networks[:len(networks)-2] 83 }