Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
cd37ec88
Commit
cd37ec88
authored
Jan 30, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
organize errors in p2p package and add a test
parent
ae1b2782
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
15 deletions
+54
-15
error.go
pkg/p2p/error.go
+30
-0
p2p.go
pkg/p2p/p2p.go
+4
-15
p2p_test.go
pkg/p2p/p2p_test.go
+20
-0
No files found.
pkg/p2p/error.go
View file @
cd37ec88
...
...
@@ -4,6 +4,15 @@
package
p2p
import
(
"errors"
"fmt"
)
// ErrPeerNotFound should be returned by p2p service methods when the requested
// peer is not found.
var
ErrPeerNotFound
=
errors
.
New
(
"peer not found"
)
// DisconnectError is an error that is specifically handled inside p2p. If returned by specific protocol
// handler it causes peer disconnect.
type
DisconnectError
struct
{
...
...
@@ -25,3 +34,24 @@ func (e *DisconnectError) Unwrap() error { return e.err }
func
(
e
*
DisconnectError
)
Error
()
string
{
return
e
.
err
.
Error
()
}
// IncompatibleStreamError is the error that should be returned by p2p service
// NewStream method when the stream or its version is not supported.
type
IncompatibleStreamError
struct
{
err
error
}
// NewIncompatibleStreamError wraps the error that is the cause of stream
// incompatibility with IncompatibleStreamError that it can be detected and
// returns it.
func
NewIncompatibleStreamError
(
err
error
)
*
IncompatibleStreamError
{
return
&
IncompatibleStreamError
{
err
:
err
}
}
// Unwrap returns an underlying error.
func
(
e
*
IncompatibleStreamError
)
Unwrap
()
error
{
return
e
.
err
}
// Error implements function of the standard go error interface.
func
(
e
*
IncompatibleStreamError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"incompatible stream: %v"
,
e
.
err
)
}
pkg/p2p/p2p.go
View file @
cd37ec88
...
...
@@ -6,7 +6,6 @@ package p2p
import
(
"context"
"fmt"
"io"
"github.com/ethersphere/bee/pkg/swarm"
...
...
@@ -39,23 +38,13 @@ type StreamSpec struct {
Handler
HandlerFunc
}
type
HandlerFunc
func
(
Peer
,
Stream
)
error
type
HandlerMiddleware
func
(
HandlerFunc
)
HandlerFunc
type
IncompatibleStreamError
struct
{
err
error
type
Peer
struct
{
Address
swarm
.
Address
}
func
NewIncompatibleStreamError
(
err
error
)
*
IncompatibleStreamError
{
return
&
IncompatibleStreamError
{
err
:
err
}
}
func
(
e
*
IncompatibleStreamError
)
Unwrap
()
error
{
return
e
.
err
}
type
HandlerFunc
func
(
Peer
,
Stream
)
error
func
(
e
*
IncompatibleStreamError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"incompatible stream: %v"
,
e
.
err
)
}
type
HandlerMiddleware
func
(
HandlerFunc
)
HandlerFunc
func
NewSwarmStreamName
(
protocol
,
stream
,
version
string
)
string
{
return
"/swarm/"
+
protocol
+
"/"
+
stream
+
"/"
+
version
...
...
pkg/p2p/p
eer
.go
→
pkg/p2p/p
2p_test
.go
View file @
cd37ec88
...
...
@@ -2,16 +2,19 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
p2p
package
p2p
_test
import
(
"
errors
"
"
testing
"
"github.com/ethersphere/bee/pkg/
swarm
"
"github.com/ethersphere/bee/pkg/
p2p
"
)
type
Peer
struct
{
Address
swarm
.
Address
}
func
TestNewSwarmStreamName
(
t
*
testing
.
T
)
{
want
:=
"/swarm/hive/peers/1.2.0"
got
:=
p2p
.
NewSwarmStreamName
(
"hive"
,
"peers"
,
"1.2.0"
)
var
ErrPeerNotFound
=
errors
.
New
(
"peer not found"
)
if
got
!=
want
{
t
.
Errorf
(
"got %s, want %s"
,
got
,
want
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment