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
3eb465bf
Commit
3eb465bf
authored
7 years ago
by
Aviv Eyal
Committed by
Steven Allen
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Remove protocol.go
parent
a13480f0
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/echo.go
+1
-1
examples/multipro/echo.go
examples/multipro/main.go
+1
-1
examples/multipro/main.go
examples/multipro/node.go
+21
-3
examples/multipro/node.go
examples/multipro/protocol.go
+0
-24
examples/multipro/protocol.go
with
23 additions
and
29 deletions
+23
-29
examples/multipro/echo.go
View file @
3eb465bf
...
...
@@ -10,7 +10,7 @@ import (
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
uuid
"github.com/google/uuid"
"github.com/ipfs/go-ipfs/thirdparty/assert"
assert
"github.com/ipfs/go-ipfs/thirdparty/assert"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
"gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host"
)
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/main.go
View file @
3eb465bf
...
...
@@ -46,7 +46,7 @@ func main() {
log
.
Printf
(
"This is a conversation between %s and %s
\n
"
,
h1
.
ID
(),
h2
.
ID
())
//
test implemented
protocols
//
send messages using the
protocols
h1
.
Ping
(
h2
.
Host
)
h2
.
Ping
(
h1
.
Host
)
h1
.
Echo
(
h2
.
Host
)
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/node.go
View file @
3eb465bf
package
main
import
(
"log"
"time"
"bufio"
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
"github.com/gogo/protobuf/proto"
host
"gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host"
peer
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
crypto
"gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
"log
"
"time
"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf
"
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net
"
)
// node client version
...
...
@@ -115,7 +119,6 @@ func (n *Node) verifyData(data []byte, signature []byte, peerId peer.ID, pubKeyD
// helper method - generate message data shared between all node's p2p protocols
// messageId: unique for requests, copied from request for responses
func
(
n
*
Node
)
NewMessageData
(
messageId
string
,
gossip
bool
)
*
p2p
.
MessageData
{
// Add protobufs bin data for message author public key
// this is useful for authenticating messages forwarded by a node authored by another node
nodePubKey
,
err
:=
n
.
Peerstore
()
.
PubKey
(
n
.
ID
())
.
Bytes
()
...
...
@@ -131,3 +134,18 @@ func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData {
Id
:
messageId
,
Gossip
:
gossip
}
}
// 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
{
writer
:=
bufio
.
NewWriter
(
s
)
enc
:=
protobufCodec
.
Multicodec
(
nil
)
.
Encoder
(
writer
)
err
:=
enc
.
Encode
(
data
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
false
}
writer
.
Flush
()
return
true
}
This diff is collapsed.
Click to expand it.
examples/multipro/protocol.go
deleted
100644 → 0
View file @
a13480f0
package
main
import
(
"bufio"
"github.com/gogo/protobuf/proto"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
"log"
)
// 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
{
writer
:=
bufio
.
NewWriter
(
s
)
enc
:=
protobufCodec
.
Multicodec
(
nil
)
.
Encoder
(
writer
)
err
:=
enc
.
Encode
(
data
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
false
}
writer
.
Flush
()
return
true
}
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