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

Commit 7253b60

Browse files
committed
Fix
1 parent b90e22d commit 7253b60

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

protportssub.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package p2pforwarder
33
import (
44
"context"
55
"encoding/binary"
6+
"errors"
67
"fmt"
78
"io"
89

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

134+
// ErrConnReset = error Connection reset
135+
var ErrConnReset = errors.New("Connection reset")
136+
133137
func (f *Forwarder) sendOpenPortsManifestBytes(peerid peer.ID, b []byte) error {
134138
s, err := f.host.NewStream(context.Background(), peerid, portssubProtID)
135139
if err != nil {
@@ -148,12 +152,17 @@ func (f *Forwarder) sendOpenPortsManifestBytes(peerid peer.ID, b []byte) error {
148152
}
149153

150154
// Test, if connection have been reset or not
151-
_, err = io.ReadFull(s, make([]byte, 1))
155+
n, err := io.ReadFull(s, make([]byte, 1))
152156
if err != nil {
153157
s.Reset()
154158
return fmt.Errorf("sendOpenPortsManifestBytes: %s", err)
155159
}
156160

161+
if n == 0 {
162+
s.Reset()
163+
return fmt.Errorf("sendOpenPortsManifestBytes: %s", ErrConnReset)
164+
}
165+
157166
s.Close()
158167

159168
return nil

0 commit comments

Comments
 (0)