Skip to content

Commit

Permalink
Merge 794913f into ae156c4
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Jun 27, 2018
2 parents ae156c4 + 794913f commit fbb8b42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.10: QmdkYdKmXnmKRoUWzYMpc7JxDsjgLgDKVkFPzooZuvACc2
1.0.11: QmY4arpjGVVLoNaLCfMVchKtrMCkpacofZbmRM7bwk2arx
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmY6iAoG9DVgZwh5ZRcQEpa2uErAe1Hbei8qXPCjpDS9Ge",
"hash": "QmZ86eLPtXkQ1Dfa992Q8NpXArUoWWh3y728JDcWvzRrvC",
"name": "go-libp2p",
"version": "5.0.21"
"version": "6.0.5"
},
{
"author": "multiformats",
Expand All @@ -25,6 +25,6 @@
"license": "MIT/BSD",
"name": "go-libp2p-gorpc",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.0.10"
"version": "1.0.11"
}

56 changes: 13 additions & 43 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import (
"time"

logging "github.com/ipfs/go-log"
crypto "github.com/libp2p/go-libp2p-crypto"
libp2p "github.com/libp2p/go-libp2p"
host "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
peerstore "github.com/libp2p/go-libp2p-peerstore"
swarm "github.com/libp2p/go-libp2p-swarm"
basic "github.com/libp2p/go-libp2p/p2p/host/basic"
multiaddr "github.com/multiformats/go-multiaddr"
)

func init() {
Expand Down Expand Up @@ -89,45 +86,18 @@ func (t *Arith) Sleep(ctx context.Context, secs int, res *struct{}) error {
}

func makeRandomNodes() (h1, h2 host.Host) {
priv1, pub1, _ := crypto.GenerateKeyPair(crypto.RSA, 2048)
pid1, _ := peer.IDFromPublicKey(pub1)
maddr1, _ := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/19998")

priv2, pub2, _ := crypto.GenerateKeyPair(crypto.RSA, 2048)
pid2, _ := peer.IDFromPublicKey(pub2)
maddr2, _ := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/19999")

ps1 := peerstore.NewPeerstore()
ps2 := peerstore.NewPeerstore()
ps1.AddPubKey(pid1, pub1)
ps1.AddPrivKey(pid1, priv1)
ps1.AddPubKey(pid2, pub2)
ps1.AddPrivKey(pid2, priv2)
ps1.AddAddrs(pid2, []multiaddr.Multiaddr{maddr2}, peerstore.PermanentAddrTTL)

ps2.AddPubKey(pid1, pub1)
ps2.AddPrivKey(pid1, priv1)
ps2.AddPubKey(pid2, pub2)
ps2.AddPrivKey(pid2, priv2)
ps2.AddAddrs(pid1, []multiaddr.Multiaddr{maddr1}, peerstore.PermanentAddrTTL)

ctx := context.Background()
n1, _ := swarm.NewNetwork(
ctx,
[]multiaddr.Multiaddr{maddr1},
pid1,
ps1,
nil)
n2, _ := swarm.NewNetwork(
ctx,
[]multiaddr.Multiaddr{maddr2},
pid2,
ps2,
nil)

h1 = basic.New(n1)
h2 = basic.New(n2)
time.Sleep(time.Second)
h1, _ = libp2p.New(
context.Background(),
libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/19998"),
)
h2, _ = libp2p.New(
context.Background(),
libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/19999"),
)

h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), peerstore.PermanentAddrTTL)
h2.Peerstore().AddAddrs(h1.ID(), h1.Addrs(), peerstore.PermanentAddrTTL)

return
}

Expand Down

0 comments on commit fbb8b42

Please sign in to comment.