// InitConn main entry for initialization of p2p connections.
InitConn main entry for initialization of p2p connections.
// InitConn main entry for initialization of p2p connections .
func InitConn(port, nid string) error {
	lnode = NewLNode(port, nid)
	if err := lnode.initHost(); err != nil {
		return err
	}
	log.WithField("host-id", lnode.ID()).Info("Host created")
	ctx := lnode.GetContext()
	kademliaDHT, err := libp2pdht.New(ctx, lnode)
	if err != nil {
		return err
	}
	if err = kademliaDHT.Bootstrap(ctx); err != nil {
		return err
	}
	ConnectToBootstrapNodes(lnode)
	log.Warn("Announcing to peers...")
	routingDiscovery := discovery.NewRoutingDiscovery(kademliaDHT)
	discovery.Advertise(ctx, routingDiscovery, nid)
	log.Info("Announcing successful")
	log.Warn("Searching for other peers...")
	peerChan, err := routingDiscovery.FindPeers(ctx, nid)
	if err != nil {
		return err
	}
	for peer := range peerChan {
		log.WithField("peer-id", peer.ID).Info("Peer discovered!")
		if peer.ID == lnode.ID() {
			continue
		}
		lnode.AddPeer(peer.ID)
		sys.Notify("Peer connected: ", string(peer.ID))
	}
	return nil
}
func InitConn ( port , nid string ) error { lnode = NewLNode ( port , nid ) if err := lnode . initHost ( ) ; err != nil { return err } log . WithField ( " " , lnode . ID ( ) ) . Info ( " " ) ctx := lnode . GetContext ( ) kademliaDHT , err := libp2pdht . New ( ctx , lnode ) if err != nil { return err } if err = kademliaDHT . Bootstrap ( ctx ) ; err != nil { return err } ConnectToBootstrapNodes ( lnode ) log . Warn ( " " ) routingDiscovery := discovery . NewRoutingDiscovery ( kademliaDHT ) discovery . Advertise ( ctx , routingDiscovery , nid ) log . Info ( " " ) log . Warn ( " " ) peerChan , err := routingDiscovery . FindPeers ( ctx , nid ) if err != nil { return err } for peer := range peerChan { log . WithField ( " " , peer . ID ) . Info ( " " ) if peer . ID == lnode . ID ( ) { continue } lnode . AddPeer ( peer . ID ) sys . Notify ( " " , string ( peer . ID ) ) } return nil }
InitConn main entry for initialization of p2p connections.
InitConn main entry for initialization of p2p connections .
// Initialize kademlia distributed hash table from LNode host. // Connect lnode to bootstrap libp2p nodes // TODO: move routing to LNode ?