Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nickname76 committed Dec 21, 2020
1 parent b90e22d commit 7253b60
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion protportssub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package p2pforwarder
import (
"context"
"encoding/binary"
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -130,6 +131,9 @@ func (f *Forwarder) sendPortsManifestToSubscriber(peerid peer.ID, b []byte) {
f.portsSubscribersMux.Unlock()
}

// ErrConnReset = error Connection reset
var ErrConnReset = errors.New("Connection reset")

func (f *Forwarder) sendOpenPortsManifestBytes(peerid peer.ID, b []byte) error {
s, err := f.host.NewStream(context.Background(), peerid, portssubProtID)
if err != nil {
Expand All @@ -148,12 +152,17 @@ func (f *Forwarder) sendOpenPortsManifestBytes(peerid peer.ID, b []byte) error {
}

// Test, if connection have been reset or not
_, err = io.ReadFull(s, make([]byte, 1))
n, err := io.ReadFull(s, make([]byte, 1))
if err != nil {
s.Reset()
return fmt.Errorf("sendOpenPortsManifestBytes: %s", err)
}

if n == 0 {
s.Reset()
return fmt.Errorf("sendOpenPortsManifestBytes: %s", ErrConnReset)
}

s.Close()

return nil
Expand Down

0 comments on commit 7253b60

Please sign in to comment.