Commit 6a1d7097 authored by Łukasz Magiera's avatar Łukasz Magiera

p2p: turns out we need half-open streams

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent cf6ddcbf
......@@ -44,6 +44,7 @@ func (p2p *P2P) Dial(ctx context.Context, peer peer.ID, proto string, bindAddr m
listener: maListener,
}
p2p.Listeners.Register(listener)
go listener.acceptConns()
return listener, nil
......
......@@ -27,7 +27,15 @@ type Stream struct {
Registry *StreamRegistry
}
// Reset closes stream endpoints and deregisters it
// Close closes stream endpoints and deregisters it
func (s *Stream) Close() error {
s.Local.Close()
s.Remote.Close()
s.Registry.Deregister(s.Id)
return nil
}
// Rest closes stream endpoints and deregisters it
func (s *Stream) Reset() error {
s.Local.Close()
s.Remote.Reset()
......@@ -42,8 +50,12 @@ func (s *Stream) startStreaming() {
}()
go func() {
io.Copy(s.Remote, s.Local)
_, err := io.Copy(s.Remote, s.Local)
if err != nil {
s.Reset()
} else {
s.Close()
}
}()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment