mirror of
https://github.com/luxfi/p2p.git
synced 2026-10-30 15:22:55 +00:00
- Add own Sender interface with SendRequest, SendResponse, SendError, SendGossip - Add own Error struct with Code/Message fields - Update Handler interface methods to Gossip() and Request() - Remove consensus/core dependency for p2p interfaces - Rename all App* prefixed methods to simple names - Update lp118 to use p2p.Error and Request method - Update gossip to use p2p.SendConfig and Request/Gossip methods - Clean up stale type conversions
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package p2p
|
|
|
|
import "fmt"
|
|
|
|
// Error represents an application-level error for peer messaging
|
|
type Error struct {
|
|
Code int32
|
|
Message string
|
|
}
|
|
|
|
// Error implements the error interface
|
|
func (e *Error) Error() string {
|
|
if e == nil {
|
|
return ""
|
|
}
|
|
return fmt.Sprintf("app error %d: %s", e.Code, e.Message)
|
|
}
|
|
|
|
var (
|
|
// ErrUnexpected should be used to indicate that a request failed due to a
|
|
// generic error
|
|
ErrUnexpected = &Error{
|
|
Code: -1,
|
|
Message: "unexpected error",
|
|
}
|
|
// ErrUnregisteredHandler should be used to indicate that a request failed
|
|
// due to it not matching a registered handler
|
|
ErrUnregisteredHandler = &Error{
|
|
Code: -2,
|
|
Message: "unregistered handler",
|
|
}
|
|
// ErrNotValidator should be used to indicate that a request failed due to
|
|
// the requesting peer not being a validator
|
|
ErrNotValidator = &Error{
|
|
Code: -3,
|
|
Message: "not a validator",
|
|
}
|
|
// ErrThrottled should be used to indicate that a request failed due to the
|
|
// requesting peer exceeding a rate limit
|
|
ErrThrottled = &Error{
|
|
Code: -4,
|
|
Message: "throttled",
|
|
}
|
|
)
|