-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modularise p2p and add connection manager
- Loading branch information
Showing
7 changed files
with
95 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package connmgr | ||
|
||
import ( | ||
"github.com/bahner/go-ma-actor/config" | ||
"github.com/libp2p/go-libp2p/p2p/net/connmgr" | ||
p2pConnmgr "github.com/libp2p/go-libp2p/p2p/net/connmgr" | ||
) | ||
|
||
func Init() (*p2pConnmgr.BasicConnMgr, error) { | ||
|
||
withGracePeriod := connmgr.WithGracePeriod(config.GetConnMgrGracePeriod()) | ||
|
||
return p2pConnmgr.NewConnManager( | ||
config.GetLowWaterMark(), | ||
config.GetHighWaterMark(), | ||
withGracePeriod, | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package p2p | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/bahner/go-ma" | ||
"github.com/libp2p/go-libp2p/core/network" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
) | ||
|
||
var ( | ||
connectedPeers map[string]*peer.AddrInfo | ||
) | ||
|
||
// Get list of connected peers. | ||
func GetConnectedPeers(connectTimeout time.Duration) map[string]*peer.AddrInfo { | ||
|
||
for _, p := range n.Network().Peers() { | ||
|
||
if n.ConnManager().IsProtected(p, ma.RENDEZVOUS) { | ||
|
||
if n.Network().Connectedness(p) == network.Connected { | ||
|
||
connectedPeer := n.Peerstore().PeerInfo(p) | ||
|
||
connectedPeers[p.String()] = &connectedPeer | ||
} | ||
} | ||
|
||
} | ||
|
||
return connectedPeers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters