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
87b9f1a5
Commit
87b9f1a5
authored
Jan 24, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
protect libp2p peer id and overlay address maps
parent
02e75916
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletion
+10
-1
libp2p.go
pkg/p2p/libp2p/libp2p.go
+10
-1
No files found.
pkg/p2p/libp2p/libp2p.go
View file @
87b9f1a5
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"net"
"net"
"os"
"os"
"strconv"
"strconv"
"sync"
"time"
"time"
"github.com/janos/bee/pkg/p2p"
"github.com/janos/bee/pkg/p2p"
...
@@ -43,6 +44,7 @@ type Service struct {
...
@@ -43,6 +44,7 @@ type Service struct {
handshakeService
*
handshake
.
Service
handshakeService
*
handshake
.
Service
overlayToPeerID
map
[
string
]
libp2ppeer
.
ID
overlayToPeerID
map
[
string
]
libp2ppeer
.
ID
peerIDToOverlay
map
[
libp2ppeer
.
ID
]
string
peerIDToOverlay
map
[
libp2ppeer
.
ID
]
string
overlayPeerIDMu
sync
.
RWMutex
}
}
type
Options
struct
{
type
Options
struct
{
...
@@ -231,7 +233,10 @@ func (s *Service) AddProtocol(p p2p.ProtocolSpec) (err error) {
...
@@ -231,7 +233,10 @@ func (s *Service) AddProtocol(p p2p.ProtocolSpec) (err error) {
}
}
s
.
host
.
SetStreamHandlerMatch
(
id
,
matcher
,
func
(
stream
network
.
Stream
)
{
s
.
host
.
SetStreamHandlerMatch
(
id
,
matcher
,
func
(
stream
network
.
Stream
)
{
overlay
,
ok
:=
s
.
peerIDToOverlay
[
stream
.
Conn
()
.
RemotePeer
()]
peerID
:=
stream
.
Conn
()
.
RemotePeer
()
s
.
overlayPeerIDMu
.
Lock
()
overlay
,
ok
:=
s
.
peerIDToOverlay
[
peerID
]
s
.
overlayPeerIDMu
.
Unlock
()
if
!
ok
{
if
!
ok
{
// todo: handle better
// todo: handle better
fmt
.
Printf
(
"Could not fetch handshake for peerID %s
\n
"
,
stream
)
fmt
.
Printf
(
"Could not fetch handshake for peerID %s
\n
"
,
stream
)
...
@@ -288,7 +293,9 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (err error) {
...
@@ -288,7 +293,9 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (err error) {
return
nil
return
nil
}
}
func
(
s
*
Service
)
NewStream
(
ctx
context
.
Context
,
overlay
,
protocolName
,
streamName
,
version
string
)
(
p2p
.
Stream
,
error
)
{
func
(
s
*
Service
)
NewStream
(
ctx
context
.
Context
,
overlay
,
protocolName
,
streamName
,
version
string
)
(
p2p
.
Stream
,
error
)
{
s
.
overlayPeerIDMu
.
Lock
()
peerID
,
ok
:=
s
.
overlayToPeerID
[
overlay
]
peerID
,
ok
:=
s
.
overlayToPeerID
[
overlay
]
s
.
overlayPeerIDMu
.
Unlock
()
if
!
ok
{
if
!
ok
{
fmt
.
Printf
(
"Could not fetch peerID for handshake %s
\n
"
,
overlay
)
fmt
.
Printf
(
"Could not fetch peerID for handshake %s
\n
"
,
overlay
)
return
nil
,
nil
return
nil
,
nil
...
@@ -311,8 +318,10 @@ func (s *Service) newStreamForPeerID(ctx context.Context, peerID libp2ppeer.ID,
...
@@ -311,8 +318,10 @@ func (s *Service) newStreamForPeerID(ctx context.Context, peerID libp2ppeer.ID,
}
}
func
(
s
*
Service
)
addAddresses
(
overlay
string
,
peerID
libp2ppeer
.
ID
)
{
func
(
s
*
Service
)
addAddresses
(
overlay
string
,
peerID
libp2ppeer
.
ID
)
{
s
.
overlayPeerIDMu
.
Lock
()
s
.
overlayToPeerID
[
overlay
]
=
peerID
s
.
overlayToPeerID
[
overlay
]
=
peerID
s
.
peerIDToOverlay
[
peerID
]
=
overlay
s
.
peerIDToOverlay
[
peerID
]
=
overlay
s
.
overlayPeerIDMu
.
Unlock
()
}
}
func
(
s
*
Service
)
Close
()
error
{
func
(
s
*
Service
)
Close
()
error
{
...
...
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