Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
efdab230
Commit
efdab230
authored
7 years ago
by
Aviv Eyal
Committed by
Steven Allen
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Use pointers for methods to avoid copying
parent
8d6313d1
master
2018-Q4-OKR
feat/protobuf
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-nza0mn
jenkinsfile
multistream-ping
punching
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
examples/multipro/echo.go
+3
-3
examples/multipro/echo.go
examples/multipro/node.go
+6
-6
examples/multipro/node.go
examples/multipro/pb/p2p.proto
+2
-2
examples/multipro/pb/p2p.proto
examples/multipro/ping.go
+3
-3
examples/multipro/ping.go
examples/multipro/protocol.go
+1
-1
examples/multipro/protocol.go
with
15 additions
and
15 deletions
+15
-15
examples/multipro/echo.go
View file @
efdab230
...
...
@@ -33,7 +33,7 @@ func NewEchoProtocol(node *Node, done chan bool) *EchoProtocol {
}
// remote peer requests handler
func
(
e
EchoProtocol
)
onEchoRequest
(
s
inet
.
Stream
)
{
func
(
e
*
EchoProtocol
)
onEchoRequest
(
s
inet
.
Stream
)
{
// get request data
data
:=
&
p2p
.
EchoRequest
{}
decoder
:=
protobufCodec
.
Multicodec
(
nil
)
.
Decoder
(
bufio
.
NewReader
(
s
))
...
...
@@ -86,7 +86,7 @@ func (e EchoProtocol) onEchoRequest(s inet.Stream) {
}
// remote echo response handler
func
(
e
EchoProtocol
)
onEchoResponse
(
s
inet
.
Stream
)
{
func
(
e
*
EchoProtocol
)
onEchoResponse
(
s
inet
.
Stream
)
{
data
:=
&
p2p
.
EchoResponse
{}
decoder
:=
protobufCodec
.
Multicodec
(
nil
)
.
Decoder
(
bufio
.
NewReader
(
s
))
err
:=
decoder
.
Decode
(
data
)
...
...
@@ -120,7 +120,7 @@ func (e EchoProtocol) onEchoResponse(s inet.Stream) {
e
.
done
<-
true
}
func
(
e
EchoProtocol
)
Echo
(
host
host
.
Host
)
bool
{
func
(
e
*
EchoProtocol
)
Echo
(
host
host
.
Host
)
bool
{
log
.
Printf
(
"%s: Sending echo to: %s...."
,
e
.
node
.
ID
(),
host
.
ID
())
// create message data
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/node.go
View file @
efdab230
...
...
@@ -24,7 +24,7 @@ func NewNode(host host.Host, done chan bool) *Node {
return
node
}
func
(
n
Node
)
authenticateMessage
(
message
proto
.
Message
,
data
*
p2p
.
MessageData
)
bool
{
func
(
n
*
Node
)
authenticateMessage
(
message
proto
.
Message
,
data
*
p2p
.
MessageData
)
bool
{
// store a temp ref to sig and remove it from data
sign
:=
data
.
Sign
...
...
@@ -49,7 +49,7 @@ func (n Node) authenticateMessage(message proto.Message, data *p2p.MessageData)
return
n
.
verifyData
(
bin
,
[]
byte
(
sign
),
peerId
,
[]
byte
(
data
.
NodePubKey
))
}
func
(
n
Node
)
signProtoMessage
(
message
proto
.
Message
)
([]
byte
,
error
)
{
func
(
n
*
Node
)
signProtoMessage
(
message
proto
.
Message
)
([]
byte
,
error
)
{
data
,
err
:=
proto
.
Marshal
(
message
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -57,16 +57,16 @@ func (n Node) signProtoMessage(message proto.Message) ([]byte, error) {
return
n
.
signData
(
data
)
}
func
(
n
Node
)
signData
(
data
[]
byte
)
([]
byte
,
error
)
{
func
(
n
*
Node
)
signData
(
data
[]
byte
)
([]
byte
,
error
)
{
key
:=
n
.
Peerstore
()
.
PrivKey
(
n
.
ID
())
res
,
err
:=
key
.
Sign
(
data
)
return
res
,
err
}
// precondition: we have info about the signer peer in the local peer store
func
(
n
Node
)
verifyData
(
data
[]
byte
,
signature
[]
byte
,
peerId
peer
.
ID
,
pubKeyData
[]
byte
)
bool
{
func
(
n
*
Node
)
verifyData
(
data
[]
byte
,
signature
[]
byte
,
peerId
peer
.
ID
,
pubKeyData
[]
byte
)
bool
{
// todo: restore pub key from message and use it
// todo: restore pub key from message and
not from the local peer store and
use it
key
:=
n
.
Peerstore
()
.
PubKey
(
peerId
)
//todo: fix this
...
...
@@ -79,7 +79,7 @@ func (n Node) verifyData(data []byte, signature []byte, peerId peer.ID, pubKeyDa
res
,
err
:=
key
.
Verify
(
data
,
signature
)
if
err
!=
nil
{
log
.
Println
(
"Error authenticating data"
)
log
.
Println
(
"Error authenticating data"
)
return
false
}
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/pb/p2p.proto
View file @
efdab230
...
...
@@ -10,8 +10,8 @@ message MessageData {
string
id
=
3
;
// allows requesters to use request data when processing a response
bool
gossip
=
4
;
// true to have receiver peer gossip the message to neighbors
string
nodeId
=
5
;
// id of node that created the message (not the peer that may have sent it). =base58(mh(sha256(nodePubKey)))
bytes
nodePubKey
=
6
;
// node
's
Secp256k1 public key
bytes
(32bytes)
string
sign
=
7
;
// signature of message data + method specific data by message authoring node
bytes
nodePubKey
=
6
;
//
Authoring
node Secp256k1 public key (32bytes)
string
sign
=
7
;
// signature of message data + method specific data by message authoring node
}
//// ping protocol
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/ping.go
View file @
efdab230
...
...
@@ -33,7 +33,7 @@ func NewPingProtocol(node *Node, done chan bool) *PingProtocol {
}
// remote peer requests handler
func
(
p
PingProtocol
)
onPingRequest
(
s
inet
.
Stream
)
{
func
(
p
*
PingProtocol
)
onPingRequest
(
s
inet
.
Stream
)
{
// get request data
data
:=
&
p2p
.
PingRequest
{}
...
...
@@ -86,7 +86,7 @@ func (p PingProtocol) onPingRequest(s inet.Stream) {
}
// remote ping response handler
func
(
p
PingProtocol
)
onPingResponse
(
s
inet
.
Stream
)
{
func
(
p
*
PingProtocol
)
onPingResponse
(
s
inet
.
Stream
)
{
data
:=
&
p2p
.
PingResponse
{}
decoder
:=
protobufCodec
.
Multicodec
(
nil
)
.
Decoder
(
bufio
.
NewReader
(
s
))
err
:=
decoder
.
Decode
(
data
)
...
...
@@ -117,7 +117,7 @@ func (p PingProtocol) onPingResponse(s inet.Stream) {
p
.
done
<-
true
}
func
(
p
PingProtocol
)
Ping
(
host
host
.
Host
)
bool
{
func
(
p
*
PingProtocol
)
Ping
(
host
host
.
Host
)
bool
{
log
.
Printf
(
"%s: Sending ping to: %s...."
,
p
.
node
.
ID
(),
host
.
ID
())
// create message data
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/protocol.go
View file @
efdab230
...
...
@@ -37,7 +37,7 @@ func NewMessageData(node *Node, messageId string, gossip bool) *p2p.MessageData
nodePubKey
,
err
:=
node
.
Peerstore
()
.
PubKey
(
node
.
ID
())
.
Bytes
()
if
err
!=
nil
{
panic
(
"Failed to get public key for sender
node from
peer store."
)
panic
(
"Failed to get public key for sender
from local
peer store."
)
}
return
&
p2p
.
MessageData
{
ClientVersion
:
clientVersion
,
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help