A function that generates the p2p configuration options and creates a libp2p host object for the given context. The created host is returned
(ctx context.Context, nodeHostIP string, nodeHostPort int)
| 165 | // A function that generates the p2p configuration options and creates a |
| 166 | // libp2p host object for the given context. The created host is returned |
| 167 | func setupHost(ctx context.Context, nodeHostIP string, nodeHostPort int) (host.Host, *dht.IpfsDHT) { |
| 168 | // Set up the host identity options |
| 169 | prvkey, pubkey, err := crypto.GenerateKeyPair( |
| 170 | crypto.Ed25519, // Select your key type. Ed25519 are nice short |
| 171 | -1, // Select key length when possible (i.e. RSA). |
| 172 | ) |
| 173 | |
| 174 | // Handle any potential error |
| 175 | if err != nil { |
| 176 | logrus.WithFields(logrus.Fields{ |
| 177 | "error": err.Error(), |
| 178 | }).Fatalln("Failed to Generate P2P Identity Configuration!") |
| 179 | } |
| 180 | |
| 181 | _ = pubkey |
| 182 | |
| 183 | // identity := libp2p.Identity(prvkey) |
| 184 | |
| 185 | // // Trace log |
| 186 | // logrus.Traceln("Generated P2P Identity Configuration.") |
| 187 | |
| 188 | // // Set up TLS secured TCP transport and options |
| 189 | // tlstransport, err := libp2ptls.New(libp2ptls.ID, prvkey, nil) |
| 190 | // security := libp2p.Security(libp2ptls.ID, tlstransport) |
| 191 | // transport := libp2p.Transport(tcp.NewTCPTransport) |
| 192 | // Handle any potential error |
| 193 | // if err != nil { |
| 194 | // logrus.WithFields(logrus.Fields{ |
| 195 | // "error": err.Error(), |
| 196 | // }).Fatalln("Failed to Generate P2P Security and Transport Configurations!") |
| 197 | // } |
| 198 | |
| 199 | // Trace log |
| 200 | // logrus.Traceln("Generated P2P Security and Transport Configurations.") |
| 201 | |
| 202 | // multiaddrStr := "/ip4/%s/tcp/%d" |
| 203 | |
| 204 | // //default "/ip4/0.0.0.0/tcp/0" |
| 205 | // multiaddrStr = fmt.Sprintf(multiaddrStr, nodeHostIP, nodeHostPort) |
| 206 | |
| 207 | // // Set up host listener address options |
| 208 | // muladdr, err := multiaddr.NewMultiaddr(multiaddrStr) |
| 209 | |
| 210 | // logrus.Infoln("Setup Multiaddr", multiaddrStr) |
| 211 | |
| 212 | // listen := libp2p.ListenAddrs(muladdr) |
| 213 | // // Handle any potential error |
| 214 | // if err != nil { |
| 215 | // logrus.WithFields(logrus.Fields{ |
| 216 | // "error": err.Error(), |
| 217 | // }).Fatalln("Failed to Generate P2P Address Listener Configuration!") |
| 218 | // } |
| 219 | |
| 220 | // // Trace log |
| 221 | // logrus.Traceln("Generated P2P Address Listener Configuration.") |
| 222 | // // Set up the stream multiplexer and connection manager options |
| 223 | // muxer := libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport) |
| 224 | // basicConnMgr, err := connmgr.NewConnManager(100, 400, connmgr.WithGracePeriod(time.Minute)) |
no test coverage detected