Commit 4b231df9 authored by Aviv Eyal's avatar Aviv Eyal Committed by Steven Allen
Browse files

log.Fatal() -> log.Println()

parent bf7f80c3
......@@ -39,7 +39,7 @@ func (e EchoProtocol) onEchoRequest(s inet.Stream) {
decoder := protobufCodec.Multicodec(nil).Decoder(bufio.NewReader(s))
err := decoder.Decode(data)
if err != nil {
log.Fatal(err)
log.Println(err)
return
}
......@@ -48,10 +48,10 @@ func (e EchoProtocol) onEchoRequest(s inet.Stream) {
valid := e.node.authenticateMessage(data, data.MessageData)
if !valid {
log.Fatal("Failed to authenticate message")
log.Println("Failed to authenticate message")
return
} else {
log.Print("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)
......@@ -65,7 +65,7 @@ func (e EchoProtocol) onEchoRequest(s inet.Stream) {
// sign the data
signature, err := e.node.signProtoMessage(resp)
if err != nil {
log.Fatal("failed to sign response")
log.Println("failed to sign response")
return
}
......@@ -74,7 +74,7 @@ func (e EchoProtocol) onEchoRequest(s inet.Stream) {
s, respErr := e.node.NewStream(context.Background(), s.Conn().RemotePeer(), echoResponse)
if respErr != nil {
log.Fatal(respErr)
log.Println(respErr)
return
}
......@@ -98,10 +98,10 @@ func (e EchoProtocol) onEchoResponse(s inet.Stream) {
valid := e.node.authenticateMessage(data, data.MessageData)
if !valid {
log.Fatal("Failed to authenticate message")
log.Println("Failed to authenticate message")
return
} else {
log.Print("Authenticated response content generated by claimed node :-)")
log.Println("Authenticated response content generated by claimed node :-)")
}
// locate request data and remove it if found
......@@ -110,7 +110,7 @@ func (e EchoProtocol) onEchoResponse(s inet.Stream) {
// remove request from map as we have processed it here
delete(e.requests, data.MessageData.Id)
} else {
log.Print("Failed to locate request data boject for response")
log.Println("Failed to locate request data boject for response")
return
}
......@@ -130,7 +130,7 @@ func (e EchoProtocol) Echo(host host.Host) bool {
signature, err := e.node.signProtoMessage(req)
if err != nil {
log.Fatal("failed to sign message")
log.Println("failed to sign message")
return false
}
......@@ -139,7 +139,7 @@ func (e EchoProtocol) Echo(host host.Host) bool {
s, err := e.node.NewStream(context.Background(), host.ID(), echoRequest)
if err != nil {
log.Fatal(err)
log.Println(err)
return false
}
......
......@@ -33,7 +33,7 @@ func (n Node) authenticateMessage(message proto.Message, data *p2p.MessageData)
// marshall data without the sig to binary format
bin, err := proto.Marshal(message)
if err != nil {
log.Fatal(err, "failed to marshal pb message")
log.Println(err, "failed to marshal pb message")
return false
}
......@@ -42,7 +42,7 @@ func (n Node) authenticateMessage(message proto.Message, data *p2p.MessageData)
peerId, err := peer.IDB58Decode(data.NodeId)
if err != nil {
log.Fatal(err, "Failed to decode node id from base58")
log.Println(err, "Failed to decode node id from base58")
return false
}
......@@ -73,13 +73,13 @@ func (n Node) verifyData(data []byte, signature []byte, peerId peer.ID, pubKeyDa
//key, err := key.UnmarshalPublicKey(pubKeyData)
if key == nil {
log.Fatal("Failed to find public key for %s in local peer store.", peerId.String())
log.Println("Failed to find public key for %s in local peer store.", peerId.String())
return false
}
res, err := key.Verify(data, signature)
if err != nil {
log.Fatal("Error authenticating data")
log.Println("Error authenticating data")
return false
}
......
......@@ -39,7 +39,7 @@ type MessageData struct {
Id string `protobuf:"bytes,3,opt,name=id" json:"id,omitempty"`
Gossip bool `protobuf:"varint,4,opt,name=gossip" json:"gossip,omitempty"`
NodeId string `protobuf:"bytes,5,opt,name=nodeId" json:"nodeId,omitempty"`
NodePubKey string `protobuf:"bytes,6,opt,name=nodePubKey" json:"nodePubKey,omitempty"`
NodePubKey []byte `protobuf:"bytes,6,opt,name=nodePubKey,proto3" json:"nodePubKey,omitempty"`
Sign string `protobuf:"bytes,7,opt,name=sign" json:"sign,omitempty"`
}
......@@ -83,11 +83,11 @@ func (m *MessageData) GetNodeId() string {
return ""
}
func (m *MessageData) GetNodePubKey() string {
func (m *MessageData) GetNodePubKey() []byte {
if m != nil {
return m.NodePubKey
}
return ""
return nil
}
func (m *MessageData) GetSign() string {
......@@ -211,21 +211,21 @@ func init() { proto.RegisterFile("p2p.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 261 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x8f, 0x31, 0x4f, 0xfb, 0x30,
0x10, 0xc5, 0xe5, 0xb4, 0xff, 0xf4, 0x9f, 0x33, 0x65, 0xb8, 0x01, 0x59, 0x08, 0xa1, 0x28, 0x62,
0xc8, 0x94, 0x21, 0xac, 0x8c, 0x30, 0x20, 0x84, 0x54, 0x79, 0x60, 0x4f, 0x93, 0x23, 0x58, 0x6a,
0x6c, 0xd3, 0x73, 0x07, 0x3e, 0x20, 0xdf, 0x0b, 0xd5, 0x0d, 0x6a, 0xfa, 0x01, 0xca, 0xe4, 0x7b,
0xef, 0x9e, 0xef, 0xe9, 0x07, 0x99, 0xaf, 0x7d, 0xe5, 0xb7, 0x2e, 0x38, 0x5c, 0xc6, 0xa7, 0x75,
0x1b, 0xae, 0x7c, 0xed, 0x8b, 0x6f, 0x01, 0xf2, 0x95, 0x98, 0x9b, 0x9e, 0x1e, 0x9b, 0xd0, 0xe0,
0x1d, 0x2c, 0xdb, 0x8d, 0x21, 0x1b, 0xde, 0x68, 0xcb, 0xc6, 0x59, 0x25, 0x72, 0x51, 0x66, 0xfa,
0xd4, 0xc4, 0x1b, 0xc8, 0x82, 0x19, 0x88, 0x43, 0x33, 0x78, 0x95, 0xe4, 0xa2, 0x9c, 0xe9, 0xa3,
0x81, 0x97, 0x90, 0x98, 0x4e, 0xcd, 0xe2, 0xc7, 0xc4, 0x74, 0x78, 0x05, 0x69, 0xef, 0x98, 0x8d,
0x57, 0xf3, 0x5c, 0x94, 0xff, 0xf5, 0xa8, 0xf6, 0xbe, 0x75, 0x1d, 0x3d, 0x77, 0xea, 0x5f, 0xcc,
0x8e, 0x0a, 0x6f, 0x01, 0xf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x88, 0xb9, 0xee, 0xe8, 0xa9, 0x0e, 0x35, 0xde, 0xc3,
0xb2, 0xd9, 0x18, 0xb2, 0xe1, 0x9d, 0xb6, 0x6c, 0x9c, 0x55, 0x22, 0x13, 0x45, 0xaa, 0x4f, 0x21,
0xde, 0x42, 0x1a, 0x4c, 0x4f, 0x1c, 0xea, 0xde, 0xab, 0x49, 0x26, 0x8a, 0xa9, 0x3e, 0x02, 0xbc,
0x82, 0x89, 0x69, 0xd5, 0x34, 0x1e, 0x4e, 0x4c, 0x8b, 0xd7, 0x90, 0x74, 0x8e, 0xd9, 0x78, 0x35,
0xcb, 0x44, 0x71, 0xa9, 0x87, 0xb4, 0xe7, 0xd6, 0xb5, 0xf4, 0xd2, 0xaa, 0x8b, 0xb8, 0x3b, 0x24,
0xbc, 0x03, 0xd8, 0x4f, 0xab, 0xdd, 0xfa, 0x95, 0xbe, 0x55, 0x92, 0x89, 0x62, 0xa1, 0x47, 0x04,
0x11, 0x66, 0x6c, 0x3a, 0xab, 0xe6, 0xf1, 0x2a, 0xce, 0x39, 0x81, 0x5c, 0x19, 0xdb, 0x69, 0xfa,
0xda, 0x11, 0x07, 0x7c, 0x04, 0xd9, 0x1f, 0xad, 0xa2, 0x84, 0xac, 0x6e, 0xca, 0x13, 0xf7, 0x72,
0xe4, 0xad, 0xc7, 0xeb, 0xa8, 0x60, 0x3e, 0xc4, 0x28, 0x97, 0xea, 0xbf, 0x98, 0x7f, 0xc0, 0xe2,
0x50, 0xc3, 0xde, 0x59, 0xa6, 0xb3, 0xf5, 0x10, 0xc8, 0xe7, 0xe6, 0xd3, 0xfd, 0x83, 0xce, 0xa1,
0xe6, 0xbc, 0x3a, 0xeb, 0x24, 0xfe, 0xf0, 0xf0, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x96, 0x51, 0x39,
0x88, 0x88, 0x02, 0x00, 0x00,
}
......@@ -10,7 +10,7 @@ message MessageData {
string id = 3; // allows requesters to use request data when processing a response
bool gossip = 4; // true to have receiver peer gossip the message to neighbors
string nodeId = 5; // id of node that created the message (not the peer that may have sent it). =base58(mh(sha256(nodePubKey)))
string nodePubKey = 6; // node's Secp256k1 public key bytes (32bytes)
bytes nodePubKey = 6; // node's Secp256k1 public key bytes (32bytes)
string sign = 7; // signature of message data + method specific data by message authoring node
}
......
......@@ -40,7 +40,7 @@ func (p PingProtocol) onPingRequest(s inet.Stream) {
decoder := protobufCodec.Multicodec(nil).Decoder(bufio.NewReader(s))
err := decoder.Decode(data)
if err != nil {
log.Fatal(err)
log.Println(err)
return
}
......@@ -49,10 +49,10 @@ func (p PingProtocol) onPingRequest(s inet.Stream) {
valid := p.node.authenticateMessage(data, data.MessageData)
if !valid {
log.Fatal("Failed to authenticate message")
log.Println("Failed to authenticate message")
return
} else {
log.Print("Authenticated request content was generated by claimed node :-)")
log.Println("Authenticated request content was generated by claimed node :-)")
}
// generate response message
......@@ -64,7 +64,7 @@ func (p PingProtocol) onPingRequest(s inet.Stream) {
// sign the data
signature, err := p.node.signProtoMessage(resp)
if err != nil {
log.Fatal("failed to sign response")
log.Println("failed to sign response")
return
}
......@@ -74,7 +74,7 @@ func (p PingProtocol) onPingRequest(s inet.Stream) {
// send the response
s, respErr := p.node.NewStream(context.Background(), s.Conn().RemotePeer(), pingResponse)
if respErr != nil {
log.Fatal(respErr)
log.Println(respErr)
return
}
......@@ -97,10 +97,10 @@ func (p PingProtocol) onPingResponse(s inet.Stream) {
valid := p.node.authenticateMessage(data, data.MessageData)
if !valid {
log.Fatal("Failed to authenticate message")
log.Println("Failed to authenticate message")
return
} else {
log.Print("Authenticated response content generated by claimed node :-)")
log.Println("Authenticated response content generated by claimed node :-)")
}
// locate request data and remove it if found
......@@ -109,7 +109,7 @@ func (p PingProtocol) onPingResponse(s inet.Stream) {
// remove request from map as we have processed it here
delete(p.requests, data.MessageData.Id)
} else {
log.Print("Failed to locate request data boject for response")
log.Println("Failed to locate request data boject for response")
return
}
......@@ -127,7 +127,7 @@ func (p PingProtocol) Ping(host host.Host) bool {
// sign the data
signature, err := p.node.signProtoMessage(req)
if err != nil {
log.Fatal("failed to sign pb data")
log.Println("failed to sign pb data")
return false
}
......@@ -136,7 +136,7 @@ func (p PingProtocol) Ping(host host.Host) bool {
s, err := p.node.NewStream(context.Background(), host.ID(), pingRequest)
if err != nil {
log.Fatal(err)
log.Println(err)
return false
}
......
......@@ -22,7 +22,7 @@ func sendProtoMessage(data proto.Message, s inet.Stream) bool {
enc := protobufCodec.Multicodec(nil).Encoder(writer)
err := enc.Encode(data)
if err != nil {
log.Fatal(err)
log.Println(err)
return false
}
writer.Flush()
......@@ -42,7 +42,7 @@ func NewMessageData(node *Node, messageId string, gossip bool) *p2p.MessageData
return &p2p.MessageData{ClientVersion: clientVersion,
NodeId: peer.IDB58Encode(node.ID()),
NodePubKey: string(nodePubKey),
NodePubKey: nodePubKey,
Timestamp: time.Now().Unix(),
Id: messageId,
Gossip: gossip}
......
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