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
54aa54a5
Commit
54aa54a5
authored
7 years ago
by
Aviv Eyal
Committed by
Steven Allen
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Updated comments
parent
01e1a19c
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
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/multipro/main.go
+0
-1
examples/multipro/main.go
examples/multipro/node.go
+1
-1
examples/multipro/node.go
examples/multipro/pb/p2p.proto
+1
-1
examples/multipro/pb/p2p.proto
examples/multipro/ping.go
+4
-8
examples/multipro/ping.go
with
6 additions
and
11 deletions
+6
-11
examples/multipro/main.go
View file @
54aa54a5
...
...
@@ -16,7 +16,6 @@ import (
// helper method - create a lib-p2p host to listen on a port
func
makeRandomNode
(
port
int
,
done
chan
bool
)
*
Node
{
// Ignoring most errors for brevity
// See echo example for more details and better implementation
priv
,
pub
,
_
:=
crypto
.
GenerateKeyPair
(
crypto
.
RSA
,
2048
)
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/node.go
View file @
54aa54a5
...
...
@@ -33,7 +33,7 @@ func sendDataObject(data interface{}, s inet.Stream) bool {
// helper method - generate message data shared between all node's p2p protocols
// 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
{
return
&
p2p
.
MessageData
{
ClientVersion
:
clientVersion
,
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/pb/p2p.proto
View file @
54aa54a5
...
...
@@ -9,7 +9,7 @@ message MessageData {
int64
timestamp
=
2
;
// unix time
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
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
}
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/ping.go
View file @
54aa54a5
...
...
@@ -48,10 +48,8 @@ func (p *PingProtocol) onPingRequest(s inet.Stream) {
// send response to sender
log
.
Printf
(
"%s: Sending ping response to %s. Message id: %s..."
,
s
.
Conn
()
.
LocalPeer
(),
s
.
Conn
()
.
RemotePeer
(),
data
.
MessageData
.
Id
)
resp
:=
&
p2p
.
PingResponse
{
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
data
.
MessageData
.
Id
,
false
),
Message
:
fmt
.
Sprintf
(
"Ping response from %s"
,
p
.
host
.
ID
()),
}
resp
:=
&
p2p
.
PingResponse
{
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
data
.
MessageData
.
Id
,
false
),
Message
:
fmt
.
Sprintf
(
"Ping response from %s"
,
p
.
host
.
ID
())}
s
,
respErr
:=
p
.
host
.
NewStream
(
context
.
Background
(),
s
.
Conn
()
.
RemotePeer
(),
pingResponse
)
if
respErr
!=
nil
{
...
...
@@ -93,10 +91,8 @@ func (p *PingProtocol) Ping(node *Node) bool {
log
.
Printf
(
"%s: Sending ping to: %s...."
,
p
.
host
.
ID
(),
node
.
host
.
ID
())
// create message data
req
:=
&
p2p
.
PingRequest
{
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
uuid
.
New
()
.
String
(),
false
),
Message
:
fmt
.
Sprintf
(
"Ping from %s"
,
p
.
host
.
ID
()),
}
req
:=
&
p2p
.
PingRequest
{
MessageData
:
NewMessageData
(
p
.
host
.
ID
()
.
String
(),
uuid
.
New
()
.
String
(),
false
),
Message
:
fmt
.
Sprintf
(
"Ping from %s"
,
p
.
host
.
ID
())}
s
,
err
:=
p
.
host
.
NewStream
(
context
.
Background
(),
node
.
host
.
ID
(),
pingRequest
)
if
err
!=
nil
{
...
...
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