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
8d6313d1
Commit
8d6313d1
authored
7 years ago
by
Aviv Eyal
Committed by
Steven Allen
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Go frmt proj
parent
4b231df9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/multipro/echo.go
+3
-3
examples/multipro/echo.go
examples/multipro/node.go
+1
-1
examples/multipro/node.go
examples/multipro/ping.go
+3
-3
examples/multipro/ping.go
examples/multipro/protocol.go
+7
-7
examples/multipro/protocol.go
with
14 additions
and
14 deletions
+14
-14
examples/multipro/echo.go
View file @
8d6313d1
...
...
@@ -8,9 +8,9 @@ import (
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
uuid
"github.com/google/uuid"
"github.com/ipfs/go-ipfs/thirdparty/assert"
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
"gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host"
)
...
...
@@ -51,7 +51,7 @@ func (e EchoProtocol) onEchoRequest(s inet.Stream) {
log
.
Println
(
"Failed to authenticate message"
)
return
}
else
{
log
.
Println
(
"Authenticated request content was generated by author node :-)"
)
//
log.Println("Authenticated request content was generated by author node :-)")
}
log
.
Printf
(
"%s: Sending echo response to %s. Message id: %s..."
,
s
.
Conn
()
.
LocalPeer
(),
s
.
Conn
()
.
RemotePeer
(),
data
.
MessageData
.
Id
)
...
...
@@ -101,7 +101,7 @@ func (e EchoProtocol) onEchoResponse(s inet.Stream) {
log
.
Println
(
"Failed to authenticate message"
)
return
}
else
{
log
.
Println
(
"Authenticated response content generated by claimed node :-)"
)
//
log.Println("Authenticated response content generated by claimed node :-)")
}
// locate request data and remove it if found
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/node.go
View file @
8d6313d1
package
main
import
(
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"
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
"log"
)
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/ping.go
View file @
8d6313d1
...
...
@@ -8,8 +8,8 @@ import (
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
uuid
"github.com/google/uuid"
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"
)
...
...
@@ -52,7 +52,7 @@ func (p PingProtocol) onPingRequest(s inet.Stream) {
log
.
Println
(
"Failed to authenticate message"
)
return
}
else
{
log
.
Println
(
"Authenticated request content was generated by claimed node :-)"
)
//
log.Println("Authenticated request content was generated by claimed node :-)")
}
// generate response message
...
...
@@ -100,7 +100,7 @@ func (p PingProtocol) onPingResponse(s inet.Stream) {
log
.
Println
(
"Failed to authenticate message"
)
return
}
else
{
log
.
Println
(
"Authenticated response content generated by claimed node :-)"
)
//
log.Println("Authenticated response content generated by claimed node :-)")
}
// locate request data and remove it if found
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/protocol.go
View file @
8d6313d1
...
...
@@ -3,12 +3,12 @@ package main
import
(
"bufio"
p2p
"github.com/avive/go-libp2p/examples/multipro/pb"
"github.com/gogo/protobuf/proto"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
inet
"gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
"log"
"time"
"github.com/gogo/protobuf/proto"
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
)
// node version
...
...
@@ -33,7 +33,7 @@ func sendProtoMessage(data proto.Message, s inet.Stream) bool {
// messageId - unique for requests, copied from request for responses
func
NewMessageData
(
node
*
Node
,
messageId
string
,
gossip
bool
)
*
p2p
.
MessageData
{
//
this c
reate
s a
protobuf data for a public key
//
C
reate protobuf
s bin
data for a public key
nodePubKey
,
err
:=
node
.
Peerstore
()
.
PubKey
(
node
.
ID
())
.
Bytes
()
if
err
!=
nil
{
...
...
@@ -41,9 +41,9 @@ func NewMessageData(node *Node, messageId string, gossip bool) *p2p.MessageData
}
return
&
p2p
.
MessageData
{
ClientVersion
:
clientVersion
,
NodeId
:
peer
.
IDB58Encode
(
node
.
ID
()),
NodeId
:
peer
.
IDB58Encode
(
node
.
ID
()),
NodePubKey
:
nodePubKey
,
Timestamp
:
time
.
Now
()
.
Unix
(),
Id
:
messageId
,
Gossip
:
gossip
}
Timestamp
:
time
.
Now
()
.
Unix
(),
Id
:
messageId
,
Gossip
:
gossip
}
}
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