From 5dadb61c73c53cdec9938af7f4d8f20774e463c5 Mon Sep 17 00:00:00 2001 From: ak Date: Fri, 24 Aug 2018 11:56:44 -0700 Subject: [PATCH] seperate identitychain handler --- identitychain/identitychain.go | 48 --------------------- identitychain/identitychain_handler.go | 58 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 48 deletions(-) create mode 100644 identitychain/identitychain_handler.go diff --git a/identitychain/identitychain.go b/identitychain/identitychain.go index 240e37d22..575f45904 100644 --- a/identitychain/identitychain.go +++ b/identitychain/identitychain.go @@ -8,8 +8,6 @@ import ( "github.com/simple-rules/harmony-benchmark/log" "github.com/simple-rules/harmony-benchmark/p2p" - "github.com/simple-rules/harmony-benchmark/proto" - proto_identity "github.com/simple-rules/harmony-benchmark/proto/identity" "github.com/simple-rules/harmony-benchmark/waitnode" ) @@ -28,52 +26,6 @@ func (IDC *IdentityChain) shard() { return } -//IdentityChainHandler handles registration of new Identities -// This could have been its seperate package like consensus, but am avoiding creating a lot of packages. -func (IDC *IdentityChain) IdentityChainHandler(conn net.Conn) { - content, err := p2p.ReadMessageContent(conn) - if err != nil { - IDC.log.Error("Read p2p data failed") - return - } - msgCategory, err := proto.GetMessageCategory(content) - if err != nil { - IDC.log.Error("Read message category failed", "err", err) - return - } - if msgCategory != proto.IDENTITY { - IDC.log.Error("Identity Chain Recieved incorrect protocol message") - os.Exit(1) - } - msgType, err := proto.GetMessageType(content) - if err != nil { - IDC.log.Error("Read action type failed") - return - } - msgPayload, err := proto.GetMessagePayload(content) - if err != nil { - IDC.log.Error("Read message payload failed") - return - } - switch msgCategory { - case proto.IDENTITY: - actionType := proto_identity.IdentityMessageType(msgType) - switch actionType { - case proto_identity.IDENTITY: - identity_payload, err := proto_identity.GetIdentityMessagePayload(msgPayload) - if err != nil { - IDC.log.Error("identity payload not read") - } else { - fmt.Println("identity payload read") - } - NewWaitNode := waitnode.DeserializeWaitNode(identity_payload) - IDC.PendingIdentities = append(IDC.PendingIdentities, NewWaitNode) - fmt.Println(len(IDC.PendingIdentities)) - } - - } -} - // GetLatestBlock gests the latest block at the end of the chain func (IDC *IdentityChain) GetLatestBlock() *IdentityBlock { if len(IDC.Identities) == 0 { diff --git a/identitychain/identitychain_handler.go b/identitychain/identitychain_handler.go new file mode 100644 index 000000000..f9074e71c --- /dev/null +++ b/identitychain/identitychain_handler.go @@ -0,0 +1,58 @@ +package identitychain + +import ( + "fmt" + "net" + "os" + + "github.com/simple-rules/harmony-benchmark/p2p" + "github.com/simple-rules/harmony-benchmark/proto" + proto_identity "github.com/simple-rules/harmony-benchmark/proto/identity" + "github.com/simple-rules/harmony-benchmark/waitnode" +) + +//IdentityChainHandler handles registration of new Identities +// This could have been its seperate package like consensus, but am avoiding creating a lot of packages. +func (IDC *IdentityChain) IdentityChainHandler(conn net.Conn) { + content, err := p2p.ReadMessageContent(conn) + if err != nil { + IDC.log.Error("Read p2p data failed") + return + } + msgCategory, err := proto.GetMessageCategory(content) + if err != nil { + IDC.log.Error("Read message category failed", "err", err) + return + } + if msgCategory != proto.IDENTITY { + IDC.log.Error("Identity Chain Recieved incorrect protocol message") + os.Exit(1) + } + msgType, err := proto.GetMessageType(content) + if err != nil { + IDC.log.Error("Read action type failed") + return + } + msgPayload, err := proto.GetMessagePayload(content) + if err != nil { + IDC.log.Error("Read message payload failed") + return + } + switch msgCategory { + case proto.IDENTITY: + actionType := proto_identity.IdentityMessageType(msgType) + switch actionType { + case proto_identity.IDENTITY: + identityPayload, err := proto_identity.GetIdentityMessagePayload(msgPayload) + if err != nil { + IDC.log.Error("identity payload not read") + } else { + fmt.Println("identity payload read") + } + NewWaitNode := waitnode.DeserializeWaitNode(identityPayload) + IDC.PendingIdentities = append(IDC.PendingIdentities, NewWaitNode) + fmt.Println(len(IDC.PendingIdentities)) + } + + } +}