Skip to content

Commit

Permalink
add PeerID,TryAddPeerToRoutingTable,RemovePeerFromRoutingTable (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Jul 12, 2023
1 parent 6ff0e32 commit 1900f59
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ type P2P interface {
// SetBootstraps updates the host's bootstrap list
SetBootstraps(bootstrap []string)

// FindPeer searches for a peer with given ID.
// DHTFindPeer searches for a peer with given ID
DHTFindPeer(peerid string) (peer.AddrInfo, error)

// PeerID returns your own peerid
PeerID() peer.ID

// TryAddPeerToRoutingTable tries to add a peer to the Routing table
TryAddPeerToRoutingTable(peerid peer.ID) (bool, error)

// RemovePeerFromRoutingTable remove peer from routing table
RemovePeerFromRoutingTable(peerid peer.ID)

// Close p2p
Close() error

Expand Down Expand Up @@ -290,6 +299,21 @@ func (n *Node) RouteTableFindPeers(limit int) (<-chan peer.AddrInfo, error) {
return n.RoutingDiscovery.FindPeers(n.ctxQueryFromCtxCancel, n.rendezvousVersion, discovery.Limit(limit))
}

// PeerID returns for own peerid
func (n *Node) PeerID() peer.ID {
return n.IpfsDHT.PeerID()
}

// TryAddPeerToRoutingTable tries to add a peer to the routing table
func (n *Node) TryAddPeerToRoutingTable(peerid peer.ID) (bool, error) {
return n.IpfsDHT.RoutingTable().TryAddPeer(peerid, true, false)
}

// RemovePeerFromRoutingTable remove peer from routing table
func (n *Node) RemovePeerFromRoutingTable(peerid peer.ID) {
n.IpfsDHT.RoutingTable().RemovePeer(peerid)
}

// GetDiscoveredPeers
func (n *Node) GetDiscoveredPeers() <-chan *routing.QueryEvent {
return n.discoveredPeerCh
Expand Down

0 comments on commit 1900f59

Please sign in to comment.