Remove protocol.go

This commit is contained in:
Aviv Eyal 2017-11-29 13:27:47 +02:00 committed by Steven Allen
parent a13480f00a
commit 3eb465bffe
4 changed files with 23 additions and 29 deletions

View File

@ -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"
)

View File

@ -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)

View File

@ -1,13 +1,17 @@
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
}

View File

@ -1,24 +0,0 @@
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
}