catch errors in SendMessage

Signed-off-by: Leo Chen <leo@harmony.one>
pull/238/head
Leo Chen 6 years ago
parent cc322ce3ff
commit c511c4d4e0
  1. 4
      p2p/host/hostv2/hostv2.go

@ -44,7 +44,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(), "addr", sourceAddr) log.Debug("HostV2 is up!", "port", self.Port, "id", p2pHost.ID().Pretty(), "addr", sourceAddr)
h := &HostV2{ h := &HostV2{
h: p2pHost, h: p2pHost,
self: self, self: self,
@ -70,7 +70,7 @@ func (host *HostV2) BindHandlerAndServe(handler p2p.StreamHandler) {
func (host *HostV2) SendMessage(p p2p.Peer, message []byte) error { func (host *HostV2) SendMessage(p p2p.Peer, message []byte) error {
addr := fmt.Sprintf("/ip4/%s/tcp/%s", p.IP, p.Port) addr := fmt.Sprintf("/ip4/%s/tcp/%s", p.IP, p.Port)
targetAddr, err := multiaddr.NewMultiaddr(addr) targetAddr, err := multiaddr.NewMultiaddr(addr)
catchError(err)
peerID := peer.ID(addr) peerID := peer.ID(addr)
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)

Loading…
Cancel
Save