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
5340ac83
Commit
5340ac83
authored
Jan 17, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/p2p: add IncompatibleStreamError
parent
00a7f60d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
go.mod
go.mod
+1
-0
libp2p.go
pkg/p2p/libp2p/libp2p.go
+6
-2
p2p.go
pkg/p2p/p2p.go
+15
-0
No files found.
go.mod
View file @
5340ac83
...
...
@@ -25,6 +25,7 @@ require (
github.com/libp2p/go-libp2p-transport v0.1.0 // indirect
github.com/libp2p/go-stream-muxer v0.1.0 // indirect
github.com/multiformats/go-multiaddr v0.2.0
github.com/multiformats/go-multistream v0.1.0
github.com/whyrusleeping/go-smux-multiplex v3.0.16+incompatible // indirect
github.com/whyrusleeping/go-smux-multistream v2.0.2+incompatible // indirect
github.com/whyrusleeping/go-smux-yamux v2.0.9+incompatible // indirect
...
...
pkg/p2p/libp2p/libp2p.go
View file @
5340ac83
...
...
@@ -5,6 +5,8 @@ import (
"fmt"
"time"
"github.com/multiformats/go-multistream"
"github.com/janos/bee/pkg/p2p"
"github.com/libp2p/go-libp2p"
...
...
@@ -20,7 +22,6 @@ import (
libp2pquic
"github.com/libp2p/go-libp2p-quic-transport"
secio
"github.com/libp2p/go-libp2p-secio"
libp2ptls
"github.com/libp2p/go-libp2p-tls"
"github.com/multiformats/go-multiaddr"
ma
"github.com/multiformats/go-multiaddr"
)
...
...
@@ -129,7 +130,7 @@ func (s *Service) Addresses() (addrs []string, err error) {
return
addrs
,
nil
}
func
(
s
*
Service
)
Connect
(
ctx
context
.
Context
,
addr
m
ultiaddr
.
Multiaddr
)
(
peerID
string
,
err
error
)
{
func
(
s
*
Service
)
Connect
(
ctx
context
.
Context
,
addr
m
a
.
Multiaddr
)
(
peerID
string
,
err
error
)
{
// Extract the peer ID from the multiaddr.
info
,
err
:=
peer
.
AddrInfoFromP2pAddr
(
addr
)
if
err
!=
nil
{
...
...
@@ -149,6 +150,9 @@ func (s *Service) NewStream(ctx context.Context, peerID, protocolName, streamNam
swarmStreamName
:=
p2p
.
NewSwarmStreamName
(
protocolName
,
streamName
,
version
)
st
,
err
:=
s
.
host
.
NewStream
(
ctx
,
id
,
protocol
.
ID
(
swarmStreamName
))
if
err
!=
nil
{
if
err
==
multistream
.
ErrNotSupported
||
err
==
multistream
.
ErrIncorrectVersion
{
return
nil
,
p2p
.
NewIncompatibleStreamError
(
err
)
}
return
nil
,
fmt
.
Errorf
(
"create stream %q to %q: %w"
,
swarmStreamName
,
peerID
,
err
)
}
return
stream
{
st
},
nil
...
...
pkg/p2p/p2p.go
View file @
5340ac83
...
...
@@ -2,6 +2,7 @@ package p2p
import
(
"context"
"fmt"
"io"
ma
"github.com/multiformats/go-multiaddr"
...
...
@@ -44,6 +45,20 @@ type StreamSpec struct {
Handler
func
(
Peer
)
}
type
IncompatibleStreamError
struct
{
err
error
}
func
NewIncompatibleStreamError
(
err
error
)
*
IncompatibleStreamError
{
return
&
IncompatibleStreamError
{
err
:
err
}
}
func
(
e
*
IncompatibleStreamError
)
Unwrap
()
error
{
return
e
.
err
}
func
(
e
*
IncompatibleStreamError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"incompatible stream: %v"
,
e
.
err
)
}
func
NewSwarmStreamName
(
protocol
,
stream
,
version
string
)
string
{
return
"/swarm/"
+
protocol
+
"/"
+
stream
+
"/"
+
version
}
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