MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / setupHost

Function setupHost

IceFireDB-SQLite/pkg/p2p/p2p.go:167–326  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
167func 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))

Callers 1

NewP2PFunction · 0.70

Calls 2

setupKadDHTFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected