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
f12d4f94
Commit
f12d4f94
authored
Jan 20, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separate p2p Streamer from p2p Service
parent
8984999f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
12 deletions
+18
-12
main.go
cmd/bee/main.go
+8
-2
p2p.go
pkg/p2p/p2p.go
+3
-0
pingpong.go
pkg/pingpong/pingpong.go
+7
-10
No files found.
cmd/bee/main.go
View file @
f12d4f94
...
...
@@ -22,6 +22,7 @@ func main() {
//var idht *dht.IpfsDHT
// Construct P2P service.
s
,
err
:=
libp2p
.
New
(
ctx
,
libp2p
.
Options
{
// Routing: func(h host.Host) (r routing.PeerRouting, err error) {
// idht, err = dht.New(ctx, h)
...
...
@@ -32,11 +33,16 @@ func main() {
log
.
Fatal
(
"p2p service: "
,
err
)
}
pingPong
,
err
:=
pingpong
.
New
(
s
)
if
err
!=
nil
{
// Construct protocols.
pingPong
:=
pingpong
.
New
(
s
)
// Add protocols to the P2P service.
if
err
=
s
.
AddProtocol
(
pingPong
.
Protocol
());
err
!=
nil
{
log
.
Fatal
(
"pingpong service: "
,
err
)
}
// Bellow is only demo code.
addrs
,
err
:=
s
.
Addresses
()
if
err
!=
nil
{
log
.
Fatal
(
"get server addresses: "
,
err
)
...
...
pkg/p2p/p2p.go
View file @
f12d4f94
...
...
@@ -11,6 +11,9 @@ import (
type
Service
interface
{
AddProtocol
(
ProtocolSpec
)
error
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
peerID
string
,
err
error
)
}
type
Streamer
interface
{
NewStream
(
ctx
context
.
Context
,
peerID
,
protocol
,
stream
,
version
string
)
(
Stream
,
error
)
}
...
...
pkg/pingpong/pingpong.go
View file @
f12d4f94
...
...
@@ -20,15 +20,15 @@ const (
)
type
Service
struct
{
p2p
p2p
.
Service
streamer
p2p
.
Streamer
}
func
New
(
p2ps
p2p
.
Service
)
(
s
*
Service
,
err
error
)
{
s
=
&
Service
{
p2p
:
p2ps
,
}
func
New
(
streamer
p2p
.
Streamer
)
*
Service
{
return
&
Service
{
streamer
:
streamer
}
}
if
err
:=
p2ps
.
AddProtocol
(
p2p
.
ProtocolSpec
{
func
(
s
*
Service
)
Protocol
()
p2p
.
ProtocolSpec
{
return
p2p
.
ProtocolSpec
{
Name
:
protocolName
,
StreamSpecs
:
[]
p2p
.
StreamSpec
{
{
...
...
@@ -37,10 +37,7 @@ func New(p2ps p2p.Service) (s *Service, err error) {
Handler
:
s
.
Handler
,
},
},
});
err
!=
nil
{
return
nil
,
err
}
return
s
,
nil
}
func
(
s
*
Service
)
Handler
(
p
p2p
.
Peer
)
{
...
...
@@ -68,7 +65,7 @@ func (s *Service) Handler(p p2p.Peer) {
}
func
(
s
*
Service
)
Ping
(
ctx
context
.
Context
,
peerID
string
,
msgs
...
string
)
(
rtt
time
.
Duration
,
err
error
)
{
stream
,
err
:=
s
.
p2p
.
NewStream
(
ctx
,
peerID
,
protocolName
,
streamName
,
streamVersion
)
stream
,
err
:=
s
.
streamer
.
NewStream
(
ctx
,
peerID
,
protocolName
,
streamName
,
streamVersion
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"new stream: %w"
,
err
)
}
...
...
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