Skip to content
GitLab
Menu
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
54aa54a5
Commit
54aa54a5
authored
Nov 27, 2017
by
Aviv Eyal
Committed by
Steven Allen
Feb 21, 2018
Browse files
Updated comments
parent
01e1a19c
Changes
4
Show whitespace changes
Inline
Side-by-side
examples/multipro/main.go
View file @
54aa54a5
...
@@ -16,7 +16,6 @@ import (
...
@@ -16,7 +16,6 @@ import (
// helper method - create a lib-p2p host to listen on a port
// helper method - create a lib-p2p host to listen on a port
func
makeRandomNode
(
port
int
,
done
chan
bool
)
*
Node
{
func
makeRandomNode
(
port
int
,
done
chan
bool
)
*
Node
{
// Ignoring most errors for brevity
// Ignoring most errors for brevity
// See echo example for more details and better implementation
// See echo example for more details and better implementation
priv
,
pub
,
_
:=
crypto
.
GenerateKeyPair
(
crypto
.
RSA
,
2048
)
priv
,
pub
,
_
:=
crypto
.
GenerateKeyPair
(
crypto
.
RSA
,
2048
)
...
...
examples/multipro/node.go
View file @
54aa54a5
...
@@ -33,7 +33,7 @@ func sendDataObject(data interface{}, s inet.Stream) bool {
...
@@ -33,7 +33,7 @@ func sendDataObject(data interface{}, s inet.Stream) bool {
// helper method - generate message data shared between all node's p2p protocols
// helper method - generate message data shared between all node's p2p protocols
// nodeId - message author id
// nodeId - message author id
// mesageId - unique for requests, copied from request for responses
// mes
s
ageId - unique for requests, copied from request for responses
func
NewMessageData
(
nodeId
string
,
messageId
string
,
gossip
bool
)
*
p2p
.
MessageData
{
func
NewMessageData
(
nodeId
string
,
messageId
string
,
gossip
bool
)
*
p2p
.
MessageData
{
return
&
p2p
.
MessageData
{
return
&
p2p
.
MessageData
{
ClientVersion
:
clientVersion
,
ClientVersion
:
clientVersion
,
...
...
examples/multipro/pb/p2p.proto
View file @
54aa54a5
...
@@ -9,7 +9,7 @@ message MessageData {
...
@@ -9,7 +9,7 @@ message MessageData {
int64
timestamp
=
2
;
// unix time
int64
timestamp
=
2
;
// unix time
string
id
=
3
;
// allows requesters to use request data when processing a response
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
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
one
that may have
relayed
it)
string
nodeId
=
5
;
// id of node that created the message (not the
peer
that may have
sent
it)
string
sign
=
6
;
// signature of message data + method specific data by message authoring node
string
sign
=
6
;
// signature of message data + method specific data by message authoring node
}
}
...
...
examples/multipro/ping.go
View file @
54aa54a5
...
@@ -48,10 +48,8 @@ func (p *PingProtocol) onPingRequest(s inet.Stream) {
...
@@ -48,10 +48,8 @@ func (p *PingProtocol) onPingRequest(s inet.Stream) {
// send response to sender
// send response to sender
log
.
Printf
(
"%s: Sending ping response to %s. Message id: %s..."
,
s
.
Conn
()
.
LocalPeer
(),
s
.
Conn
()
.
RemotePeer
(),
data
.
MessageData
.
Id
)
log
.
Printf
(
"%s: Sending ping response to %s. Message id: %s..."
,
s
.
Conn
()
.
LocalPeer
(),
s
.
Conn
()
.
RemotePeer
(),
data
.
MessageData
.
Id
)
resp
:=
&
p2p
.
PingResponse
{
resp
:=
&
p2p
.
PingResponse
{
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
data
.
MessageData
.
Id
,
false
),
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
data
.
MessageData
.
Id
,
false
),
Message
:
fmt
.
Sprintf
(
"Ping response from %s"
,
p
.
host
.
ID
())}
Message
:
fmt
.
Sprintf
(
"Ping response from %s"
,
p
.
host
.
ID
()),
}
s
,
respErr
:=
p
.
host
.
NewStream
(
context
.
Background
(),
s
.
Conn
()
.
RemotePeer
(),
pingResponse
)
s
,
respErr
:=
p
.
host
.
NewStream
(
context
.
Background
(),
s
.
Conn
()
.
RemotePeer
(),
pingResponse
)
if
respErr
!=
nil
{
if
respErr
!=
nil
{
...
@@ -93,10 +91,8 @@ func (p *PingProtocol) Ping(node *Node) bool {
...
@@ -93,10 +91,8 @@ func (p *PingProtocol) Ping(node *Node) bool {
log
.
Printf
(
"%s: Sending ping to: %s...."
,
p
.
host
.
ID
(),
node
.
host
.
ID
())
log
.
Printf
(
"%s: Sending ping to: %s...."
,
p
.
host
.
ID
(),
node
.
host
.
ID
())
// create message data
// create message data
req
:=
&
p2p
.
PingRequest
{
req
:=
&
p2p
.
PingRequest
{
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
uuid
.
New
()
.
String
(),
false
),
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
uuid
.
New
()
.
String
(),
false
),
Message
:
fmt
.
Sprintf
(
"Ping from %s"
,
p
.
host
.
ID
())}
Message
:
fmt
.
Sprintf
(
"Ping from %s"
,
p
.
host
.
ID
()),
}
s
,
err
:=
p
.
host
.
NewStream
(
context
.
Background
(),
node
.
host
.
ID
(),
pingRequest
)
s
,
err
:=
p
.
host
.
NewStream
(
context
.
Background
(),
node
.
host
.
ID
(),
pingRequest
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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