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

Function NewP2P

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

* A constructor function that generates and returns a P2P object. Constructs a libp2p host with TLS encrypted secure transportation that works over a TCP transport connection using a Yamux Stream Multiplexer and uses UPnP for the NAT traversal. A Kademlia DHT is then bootstrapped on this host usin

(serviceName string, nodeHostIP string, nodeHostPort int)

Source from the content-addressed store, hash-verified

59*/
60
61func NewP2P(serviceName string, nodeHostIP string, nodeHostPort int) *P2P {
62 // Setup a background context
63 ctx := context.Background()
64
65 // Setup a P2P Host Node
66 nodehost, kaddht := setupHost(ctx, nodeHostIP, nodeHostPort)
67 // Debug log
68 logrus.Infoln("Setup the p2p host,listen on", nodehost.Addrs())
69 log.Println("MY P2P Node ID",nodehost.ID())
70
71 // Bootstrap the Kad DHT
72 bootstrapDHT(ctx, nodehost, kaddht)
73
74 // Debug log
75 logrus.Debugln("Bootstrapped the Kademlia DHT and Connected to Bootstrap Peers")
76
77 // Create a peer discovery service using the Kad DHT
78 routingdiscovery := discoveryRouting.NewRoutingDiscovery(kaddht)
79 // Debug log
80 logrus.Debugln("Created the Peer Discovery Service.")
81
82 // Create a PubSub handler with the routing discovery PubSu
83 pubsubhandler := setupPubSub(ctx, nodehost, routingdiscovery)
84 // Debug log
85 logrus.Debugln("Created the PubSub Handler.")
86
87 // Return the P2P object
88 return &P2P{
89 Ctx: ctx,
90 Host: nodehost,
91 KadDHT: kaddht,
92 Discovery: routingdiscovery,
93 PubSub: pubsubhandler,
94 service: serviceName,
95 }
96}
97
98// A method of P2P to connect to service peers.
99// This method uses the Advertise() functionality of the Peer Discovery Service

Callers 1

InitSQLiteFunction · 0.92

Calls 3

setupHostFunction · 0.70
bootstrapDHTFunction · 0.70
setupPubSubFunction · 0.70

Tested by

no test coverage detected