-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(benchmarks): add p2p stress test (#91)
- Loading branch information
1 parent
bd2d62f
commit d88611c
Showing
2 changed files
with
120 additions
and
7 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
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,40 @@ | ||
package testnet | ||
|
||
import ( | ||
"context" | ||
|
||
gsnet "github.com/ipfs/go-graphsync/network" | ||
|
||
"github.com/libp2p/go-libp2p-core/peer" | ||
tnet "github.com/libp2p/go-libp2p-testing/net" | ||
mockpeernet "github.com/libp2p/go-libp2p/p2p/net/mock" | ||
) | ||
|
||
type peernet struct { | ||
mockpeernet.Mocknet | ||
} | ||
|
||
// StreamNet is a testnet that uses libp2p's MockNet | ||
func StreamNet(ctx context.Context, net mockpeernet.Mocknet) Network { | ||
return &peernet{net} | ||
} | ||
|
||
func (pn *peernet) Adapter(p tnet.Identity) gsnet.GraphSyncNetwork { | ||
client, err := pn.Mocknet.AddPeer(p.PrivateKey(), p.Address()) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
pn.Mocknet.LinkAll() | ||
return gsnet.NewFromLibp2pHost(client) | ||
} | ||
|
||
func (pn *peernet) HasPeer(p peer.ID) bool { | ||
for _, member := range pn.Mocknet.Peers() { | ||
if p == member { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
var _ Network = (*peernet)(nil) |