diff --git a/p2p/host/hostv2/hostv2.go b/p2p/host/hostv2/hostv2.go index a6164ccf9..ada6e4479 100644 --- a/p2p/host/hostv2/hostv2.go +++ b/p2p/host/hostv2/hostv2.go @@ -35,10 +35,9 @@ func (host *HostV2) Peerstore() peerstore.Peerstore { // New creates a host for p2p communication func New(self p2p.Peer) *HostV2 { - addr := fmt.Sprintf("/ip4/%s/tcp/%s", self.IP, self.Port) - sourceAddr, err := multiaddr.NewMultiaddr(addr) + sourceAddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", self.Port)) catchError(err) - priv := addrToPrivKey(addr) + priv := addrToPrivKey(fmt.Sprintf("/ip4/%s/tcp/%s", self.IP, self.Port)) p2pHost, err := libp2p.New(context.Background(), libp2p.ListenAddrs(sourceAddr), libp2p.Identity(priv), @@ -47,7 +46,7 @@ func New(self p2p.Peer) *HostV2 { // libp2p.EnableRelay; libp2p.Routing; ) catchError(err) - log.Debug("Host is up!", "port", self.Port, "id", p2pHost.ID().Pretty(), "addrs", sourceAddr) + log.Debug("Host is up!", "port", self.Port, "id", p2pHost.ID().Pretty(), "addr", sourceAddr) h := &HostV2{ h: p2pHost, self: self, @@ -78,7 +77,10 @@ func (host *HostV2) SendMessage(p p2p.Peer, message []byte) error { peerID, _ := peer.IDFromPrivateKey(priv) host.Peerstore().AddAddrs(peerID, []multiaddr.Multiaddr{targetAddr}, peerstore.PermanentAddrTTL) s, err := host.h.NewStream(context.Background(), peerID, ProtocolID) - catchError(err) + if err != nil { + log.Error("Failed to send message", "from", host.self, "to", p, "error", err) + return err + } // Create a buffered stream so that read and writes are non blocking. w := bufio.NewWriter(bufio.NewWriter(s)) diff --git a/p2p/p2p.go b/p2p/p2p.go index 3818c4088..287837387 100644 --- a/p2p/p2p.go +++ b/p2p/p2p.go @@ -1,6 +1,8 @@ package p2p import ( + "net" + "github.com/dedis/kyber" ) @@ -16,3 +18,5 @@ type Peer struct { ValidatorID int // -1 is the default value, means not assigned any validator ID in the shard // TODO(minhdoan, rj): use this Ready to not send/broadcast to this peer if it wasn't available. } + +func (p Peer) String() string { return net.JoinHostPort(p.IP, p.Port) } diff --git a/test/deploy.sh b/test/deploy.sh index 4ad223d98..9a4869a92 100755 --- a/test/deploy.sh +++ b/test/deploy.sh @@ -115,7 +115,7 @@ done < $config # Emulate node offline (sleep 45; killnode $KILLPORT) & -echo "launching txgen ..."Z +echo "launching txgen ..." if [ "$TXGEN" == "true" ]; then echo "launching txgen ..." $ROOT/bin/txgen -log_folder $log_folder -duration $DURATION