You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
6 years ago
|
package beaconchain
|
||
|
|
||
|
import (
|
||
6 years ago
|
"github.com/harmony-one/harmony/p2p"
|
||
|
"github.com/harmony-one/harmony/proto"
|
||
|
proto_identity "github.com/harmony-one/harmony/proto/identity"
|
||
6 years ago
|
)
|
||
|
|
||
6 years ago
|
// BeaconChainHandler handles registration of new Identities
|
||
6 years ago
|
func (bc *BeaconChain) BeaconChainHandler(s p2p.Stream) {
|
||
|
content, err := p2p.ReadMessageContent(s)
|
||
6 years ago
|
if err != nil {
|
||
6 years ago
|
bc.log.Error("Read p2p data failed")
|
||
6 years ago
|
return
|
||
|
}
|
||
|
msgCategory, err := proto.GetMessageCategory(content)
|
||
|
if err != nil {
|
||
6 years ago
|
bc.log.Error("Read message category failed", "err", err)
|
||
6 years ago
|
return
|
||
|
}
|
||
|
msgType, err := proto.GetMessageType(content)
|
||
|
if err != nil {
|
||
6 years ago
|
bc.log.Error("Read action type failed")
|
||
6 years ago
|
return
|
||
|
}
|
||
|
msgPayload, err := proto.GetMessagePayload(content)
|
||
|
if err != nil {
|
||
6 years ago
|
bc.log.Error("Read message payload failed")
|
||
6 years ago
|
return
|
||
|
}
|
||
6 years ago
|
identityMsgPayload, err := proto_identity.GetIdentityMessagePayload(msgPayload)
|
||
|
if err != nil {
|
||
6 years ago
|
bc.log.Error("Read message payload failed")
|
||
6 years ago
|
return
|
||
|
}
|
||
6 years ago
|
switch msgCategory {
|
||
|
case proto.Identity:
|
||
6 years ago
|
actionType := proto_identity.IDMessageType(msgType)
|
||
6 years ago
|
switch actionType {
|
||
|
case proto_identity.Identity:
|
||
6 years ago
|
bc.log.Info("Message category is of the type identity protocol, which is correct!")
|
||
6 years ago
|
idMsgType, err := proto_identity.GetIdentityMessageType(msgPayload)
|
||
|
if err != nil {
|
||
6 years ago
|
bc.log.Error("Error finding the identity message type")
|
||
6 years ago
|
}
|
||
|
switch idMsgType {
|
||
|
case proto_identity.Register:
|
||
6 years ago
|
bc.log.Info("Identity Message Type is of the type Register")
|
||
|
bc.AcceptConnections(identityMsgPayload)
|
||
|
default:
|
||
|
panic("Unrecognized identity message type")
|
||
6 years ago
|
}
|
||
6 years ago
|
default:
|
||
|
panic("Unrecognized message category")
|
||
6 years ago
|
}
|
||
|
|
||
|
}
|
||
|
}
|