Commit f373ffbc authored by Petar Radovic's avatar Petar Radovic

move error from libp2p to p2p

parent 8e918782
......@@ -2,26 +2,26 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libp2p
package p2p
// This error is handled specially by libp2p. If returned by specific protocol
// DisconnectError is an error that is specifically handled inside p2p. If returned by specific protocol
// handler it causes peer disconnect.
type disconnectError struct {
type DisconnectError struct {
err error
}
// Disconnect wraps error and creates a special error that is treated specially
// by libp2p. It causes peer to disconnect.
// by p2p. It causes peer to disconnect.
func Disconnect(err error) error {
return &disconnectError{
return &DisconnectError{
err: err,
}
}
// Unwrap returns an underlying error.
func (e *disconnectError) Unwrap() error { return e.err }
func (e *DisconnectError) Unwrap() error { return e.err }
// Error implements function of the standard go error interface.
func (e *disconnectError) Error() string {
func (e *DisconnectError) Error() string {
return e.err.Error()
}
......@@ -268,7 +268,7 @@ func (s *Service) AddProtocol(p p2p.ProtocolSpec) (err error) {
s.metrics.HandledStreamCount.Inc()
if err := ss.Handler(p2p.Peer{Address: overlay}, stream); err != nil {
var e *disconnectError
var e *p2p.DisconnectError
if errors.Is(err, e) {
// todo: test connection close and refactor
s.peers.remove(peerID)
......
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