Commit 3eb465bf authored by Aviv Eyal's avatar Aviv Eyal Committed by Steven Allen
Browse files

Remove protocol.go

parent a13480f0
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
p2p "github.com/avive/go-libp2p/examples/multipro/pb" p2p "github.com/avive/go-libp2p/examples/multipro/pb"
uuid "github.com/google/uuid" 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" protobufCodec "github.com/multiformats/go-multicodec/protobuf"
"gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host" "gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host"
) )
......
...@@ -46,7 +46,7 @@ func main() { ...@@ -46,7 +46,7 @@ func main() {
log.Printf("This is a conversation between %s and %s\n", h1.ID(), h2.ID()) 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) h1.Ping(h2.Host)
h2.Ping(h1.Host) h2.Ping(h1.Host)
h1.Echo(h2.Host) h1.Echo(h2.Host)
......
package main package main
import ( import (
"log"
"time"
"bufio"
p2p "github.com/avive/go-libp2p/examples/multipro/pb" p2p "github.com/avive/go-libp2p/examples/multipro/pb"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
host "gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host" host "gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host"
peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer" peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto" crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
"log" protobufCodec "github.com/multiformats/go-multicodec/protobuf"
"time" inet "gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net"
) )
// node client version // node client version
...@@ -115,7 +119,6 @@ func (n *Node) verifyData(data []byte, signature []byte, peerId peer.ID, pubKeyD ...@@ -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 // helper method - generate message data shared between all node's p2p protocols
// messageId: unique for requests, copied from request for responses // messageId: unique for requests, copied from request for responses
func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData { func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData {
// Add protobufs bin data for message author public key // Add protobufs bin data for message author public key
// this is useful for authenticating messages forwarded by a node authored by another node // this is useful for authenticating messages forwarded by a node authored by another node
nodePubKey, err := n.Peerstore().PubKey(n.ID()).Bytes() nodePubKey, err := n.Peerstore().PubKey(n.ID()).Bytes()
...@@ -131,3 +134,18 @@ func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData { ...@@ -131,3 +134,18 @@ func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData {
Id: messageId, Id: messageId,
Gossip: gossip} 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
}
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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment