[NOD-1223] Reorganize project (#868)

* [NOD-1223] Move all network stuff into a new network package.

* [NOD-1223] Delete the unused package testutil.

* [NOD-1223] Move infrastructure stuff into a new instrastructure package.

* [NOD-1223] Move domain stuff into a new domain package.
This commit is contained in:
stasatdaglabs
2020-08-13 17:27:25 +03:00
committed by GitHub
parent 0bf1052abf
commit 8a4ece1101
501 changed files with 593 additions and 897 deletions

View File

@@ -0,0 +1,52 @@
package protocolerrors
import "github.com/pkg/errors"
// ProtocolError is an error that signifies a violation
// of the peer-to-peer protocol
type ProtocolError struct {
ShouldBan bool
Cause error
}
func (e *ProtocolError) Error() string {
return e.Cause.Error()
}
func (e *ProtocolError) Unwrap() error {
return e.Cause
}
// Errorf formats according to a format specifier and returns the string
// as a ProtocolError.
func Errorf(shouldBan bool, format string, args ...interface{}) error {
return &ProtocolError{
ShouldBan: shouldBan,
Cause: errors.Errorf(format, args...),
}
}
// New returns a ProtocolError with the supplied message.
// New also records the stack trace at the point it was called.
func New(shouldBan bool, message string) error {
return &ProtocolError{
ShouldBan: shouldBan,
Cause: errors.New(message),
}
}
// Wrap wraps the given error and returns it as a ProtocolError.
func Wrap(shouldBan bool, err error, message string) error {
return &ProtocolError{
ShouldBan: shouldBan,
Cause: errors.Wrap(err, message),
}
}
// Wrapf wraps the given error with the given format and returns it as a ProtocolError.
func Wrapf(shouldBan bool, err error, format string, args ...interface{}) error {
return &ProtocolError{
ShouldBan: shouldBan,
Cause: errors.Wrapf(err, format, args...),
}
}