fix p2p v2 on aws and for surviving from node killing. (#204)

* fix p2p v2 on aws and for surviving from node killing.

* update addrs

* fix typo
pull/213/head
Richard Liu 6 years ago committed by GitHub
parent 3cb54087b7
commit 7538f64d7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      p2p/host/hostv2/hostv2.go
  2. 4
      p2p/p2p.go
  3. 2
      test/deploy.sh

@ -35,10 +35,9 @@ func (host *HostV2) Peerstore() peerstore.Peerstore {
// New creates a host for p2p communication // New creates a host for p2p communication
func New(self p2p.Peer) *HostV2 { func New(self p2p.Peer) *HostV2 {
addr := fmt.Sprintf("/ip4/%s/tcp/%s", self.IP, self.Port) sourceAddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", self.Port))
sourceAddr, err := multiaddr.NewMultiaddr(addr)
catchError(err) catchError(err)
priv := addrToPrivKey(addr) priv := addrToPrivKey(fmt.Sprintf("/ip4/%s/tcp/%s", self.IP, self.Port))
p2pHost, err := libp2p.New(context.Background(), p2pHost, err := libp2p.New(context.Background(),
libp2p.ListenAddrs(sourceAddr), libp2p.ListenAddrs(sourceAddr),
libp2p.Identity(priv), libp2p.Identity(priv),
@ -47,7 +46,7 @@ func New(self p2p.Peer) *HostV2 {
// libp2p.EnableRelay; libp2p.Routing; // libp2p.EnableRelay; libp2p.Routing;
) )
catchError(err) 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 := &HostV2{
h: p2pHost, h: p2pHost,
self: self, self: self,
@ -78,7 +77,10 @@ func (host *HostV2) SendMessage(p p2p.Peer, message []byte) error {
peerID, _ := peer.IDFromPrivateKey(priv) peerID, _ := peer.IDFromPrivateKey(priv)
host.Peerstore().AddAddrs(peerID, []multiaddr.Multiaddr{targetAddr}, peerstore.PermanentAddrTTL) host.Peerstore().AddAddrs(peerID, []multiaddr.Multiaddr{targetAddr}, peerstore.PermanentAddrTTL)
s, err := host.h.NewStream(context.Background(), peerID, ProtocolID) 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. // Create a buffered stream so that read and writes are non blocking.
w := bufio.NewWriter(bufio.NewWriter(s)) w := bufio.NewWriter(bufio.NewWriter(s))

@ -1,6 +1,8 @@
package p2p package p2p
import ( import (
"net"
"github.com/dedis/kyber" "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 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. // 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) }

@ -115,7 +115,7 @@ done < $config
# Emulate node offline # Emulate node offline
(sleep 45; killnode $KILLPORT) & (sleep 45; killnode $KILLPORT) &
echo "launching txgen ..."Z echo "launching txgen ..."
if [ "$TXGEN" == "true" ]; then if [ "$TXGEN" == "true" ]; then
echo "launching txgen ..." echo "launching txgen ..."
$ROOT/bin/txgen -log_folder $log_folder -duration $DURATION $ROOT/bin/txgen -log_folder $log_folder -duration $DURATION

Loading…
Cancel
Save