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
05928a94
Commit
05928a94
authored
7 years ago
by
Aviv Eyal
Committed by
Steven Allen
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Make sendProtoMessage a method
parent
3eb465bf
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/README.md
+1
-1
examples/multipro/README.md
examples/multipro/echo.go
+2
-2
examples/multipro/echo.go
examples/multipro/node.go
+3
-4
examples/multipro/node.go
examples/multipro/ping.go
+3
-4
examples/multipro/ping.go
with
9 additions
and
11 deletions
+9
-11
examples/multipro/README.md
View file @
05928a94
...
...
@@ -47,6 +47,6 @@ The idea is to use lib-p2p protocol multiplexing on a per-message basis.
5.
Full access to request data when processing a response.
## Author
@avive
This diff is collapsed.
Click to expand it.
examples/multipro/echo.go
View file @
05928a94
...
...
@@ -80,7 +80,7 @@ func (e *EchoProtocol) onEchoRequest(s inet.Stream) {
return
}
ok
:=
sendProtoMessage
(
resp
,
s
)
ok
:=
e
.
node
.
sendProtoMessage
(
resp
,
s
)
if
ok
{
log
.
Printf
(
"%s: Echo response to %s sent."
,
s
.
Conn
()
.
LocalPeer
()
.
String
(),
s
.
Conn
()
.
RemotePeer
()
.
String
())
...
...
@@ -143,7 +143,7 @@ func (e *EchoProtocol) Echo(host host.Host) bool {
return
false
}
ok
:=
sendProtoMessage
(
req
,
s
)
ok
:=
e
.
node
.
sendProtoMessage
(
req
,
s
)
if
!
ok
{
return
false
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/node.go
View file @
05928a94
package
main
import
(
"bufio"
"log"
"time"
"bufio"
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
"github.com/gogo/protobuf/proto"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
host
"gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host"
peer
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
crypto
"gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
)
...
...
@@ -37,7 +37,6 @@ func NewNode(host host.Host, done chan bool) *Node {
// message: a protobufs go data object
// data: common p2p message data
func
(
n
*
Node
)
authenticateMessage
(
message
proto
.
Message
,
data
*
p2p
.
MessageData
)
bool
{
// store a temp ref to signature and remove it from message data
// sign is a string to allow easy reset to zero-value (empty string)
sign
:=
data
.
Sign
...
...
@@ -138,7 +137,7 @@ func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData {
// helper method - writes a protobuf go data object to a network stream
// data: reference of protobuf go data object to send (not the object itself)
// s: network stream to write the data to
func
sendProtoMessage
(
data
proto
.
Message
,
s
inet
.
Stream
)
bool
{
func
(
n
*
Node
)
sendProtoMessage
(
data
proto
.
Message
,
s
inet
.
Stream
)
bool
{
writer
:=
bufio
.
NewWriter
(
s
)
enc
:=
protobufCodec
.
Multicodec
(
nil
)
.
Encoder
(
writer
)
err
:=
enc
.
Encode
(
data
)
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/ping.go
View file @
05928a94
...
...
@@ -6,12 +6,11 @@ import (
"fmt"
"log"
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
uuid
"github.com/google/uuid"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
"gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host"
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
)
// pattern: /protocol-name/request-or-response-message/version
...
...
@@ -76,7 +75,7 @@ func (p *PingProtocol) onPingRequest(s inet.Stream) {
return
}
ok
:=
sendProtoMessage
(
resp
,
s
)
ok
:=
p
.
node
.
sendProtoMessage
(
resp
,
s
)
if
ok
{
log
.
Printf
(
"%s: Ping response to %s sent."
,
s
.
Conn
()
.
LocalPeer
()
.
String
(),
s
.
Conn
()
.
RemotePeer
()
.
String
())
...
...
@@ -136,7 +135,7 @@ func (p *PingProtocol) Ping(host host.Host) bool {
return
false
}
ok
:=
sendProtoMessage
(
req
,
s
)
ok
:=
p
.
node
.
sendProtoMessage
(
req
,
s
)
if
!
ok
{
return
false
...
...
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