mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-23 13:44:27 +08:00
p2p: Only use reset on streams
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -386,7 +386,7 @@ var p2pStreamCloseCmd = &cmds.Command{
|
||||
if !closeAll && handlerID != stream.Id {
|
||||
continue
|
||||
}
|
||||
stream.Close()
|
||||
stream.Reset()
|
||||
if !closeAll {
|
||||
break
|
||||
}
|
||||
|
@ -27,14 +27,6 @@ type Stream struct {
|
||||
Registry *StreamRegistry
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Reset closes stream endpoints and deregisters it
|
||||
func (s *Stream) Reset() error {
|
||||
s.Local.Close()
|
||||
@ -45,21 +37,13 @@ func (s *Stream) Reset() error {
|
||||
|
||||
func (s *Stream) startStreaming() {
|
||||
go func() {
|
||||
_, err := io.Copy(s.Local, s.Remote)
|
||||
if err != nil {
|
||||
s.Reset()
|
||||
} else {
|
||||
s.Close()
|
||||
}
|
||||
io.Copy(s.Local, s.Remote)
|
||||
s.Reset()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
_, err := io.Copy(s.Remote, s.Local)
|
||||
if err != nil {
|
||||
s.Reset()
|
||||
} else {
|
||||
s.Close()
|
||||
}
|
||||
io.Copy(s.Remote, s.Local)
|
||||
s.Reset()
|
||||
}()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user