Skip to content

Commit

Permalink
Merge pull request #118 from NIC619/fix_#116
Browse files Browse the repository at this point in the history
Fix #116
  • Loading branch information
NIC619 authored Dec 3, 2018
2 parents 36daa44 + 34a1f12 commit de861e8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sharding-p2p-poc

[![Build Status](https://travis-ci.org/ethresearch/sharding-p2p-poc.svg?branch=master)](https://travis-ci.org/ethresearch/sharding-p2p-poc) [![](https://img.shields.io/badge/gitter-sharding--p2p--poc-ed1965.svg)](https://gitter.im/ethresearch/sharding-p2p-poc)
[![Build Status](https://travis-ci.org/ethresearch/sharding-p2p-poc.svg?branch=master)](https://travis-ci.org/ethresearch/sharding-p2p-poc) [![](https://img.shields.io/badge/gitter-sharding--p2p--poc-ed1965.svg)](https://gitter.im/sharding-p2p-testing/Lobby)

> This is the poc of ethereum sharding p2p layer with pubsub in libp2p, based on the idea from the [slide](
https://docs.google.com/presentation/d/11a0jibNz0fyUnsWt9fa2MmghHANdHAAABa0TV7EieHs/edit?usp=sharing).
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ func makeNode(
ctx,
libp2p.Identity(priv),
libp2p.ListenAddrStrings(listenAddrString),
libp2p.DisableRelay(),
)
if err != nil {
return nil, err
Expand Down
7 changes: 2 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ func makeUnbootstrappedNode(t *testing.T, ctx context.Context, number int) *Node
}

func connect(t *testing.T, ctx context.Context, a, b *Node) {
peerid, targetAddr, err := parseAddr(b.GetFullAddr())
if err != nil {
t.Errorf("Failed to parse peer address: %s, err: %v", b.GetFullAddr(), err)
}
a.Peerstore().AddAddr(peerid, targetAddr, pstore.PermanentAddrTTL)
peerid := b.ID()
a.Peerstore().AddAddrs(peerid, b.Addrs(), pstore.PermanentAddrTTL)

if err := a.Connect(ctx, a.Peerstore().PeerInfo(peerid)); err != nil {
t.Errorf("Failed to connect to peer %v, err: %v", peerid, err)
Expand Down
12 changes: 0 additions & 12 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package main

import (
"context"
"fmt"

host "github.com/libp2p/go-libp2p-host"
kaddht "github.com/libp2p/go-libp2p-kad-dht"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
pubsub "github.com/libp2p/go-libp2p-pubsub"
ma "github.com/multiformats/go-multiaddr"
)

type Node struct {
Expand Down Expand Up @@ -45,16 +43,6 @@ func NewNode(ctx context.Context, h host.Host, dht *kaddht.IpfsDHT, eventNotifie
return node
}

func (n *Node) GetFullAddr() string {
hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s", n.ID().Pretty()))

// Now we can build a full multiaddress to reach this host
// by encapsulating both addresses:
addr := n.Addrs()[0]
fullAddr := addr.Encapsulate(hostAddr)
return fullAddr.String()
}

// TODO: should be changed to `Knows` and `HasConnections`
func (n *Node) IsPeer(peerID peer.ID) bool {
for _, value := range n.Peerstore().Peers() {
Expand Down
14 changes: 6 additions & 8 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,20 @@ func (s *server) AddPeer(

logger.Debugf("rpcserver:AddPeer: ip=%v, port=%v, seed=%v", req.Ip, req.Port, req.Seed)
_, targetPID, err := makeKey(int(req.Seed))
mAddr := fmt.Sprintf(
"/ip4/%s/tcp/%d/ipfs/%s",
req.Ip,
req.Port,
targetPID.Pretty(),
)
if err != nil {
errMsg := fmt.Errorf("Failed to generate peer key/ID with seed: %v, err: %v", req.Seed, err)
logger.FinishWithErr(spanctx, errMsg)
logger.Error(errMsg.Error())
return nil, errMsg
}

peerid, targetAddr, err := parseAddr(mAddr)
peerid := targetPID
targetAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", req.Ip, req.Port))
if err != nil {
errMsg := fmt.Errorf("Failed to parse peer address: %s, err: %v", mAddr, err)
errMsg := fmt.Errorf(
"Failed to convert %s to multiaddr format, err: %v",
fmt.Sprintf("/ip4/%s/tcp/%d", req.Ip, req.Port),
err)
logger.FinishWithErr(spanctx, errMsg)
logger.Error(errMsg.Error())
return nil, errMsg
Expand Down

0 comments on commit de861e8

Please sign in to comment.