message handler
(ctx actor.Context)
| 52 | |
| 53 | //message handler |
| 54 | func (this *P2PActor) Receive(ctx actor.Context) { |
| 55 | switch msg := ctx.Message().(type) { |
| 56 | case *actor.Restarting: |
| 57 | log.Warn("[p2p]actor restarting") |
| 58 | case *actor.Stopping: |
| 59 | log.Warn("[p2p]actor stopping") |
| 60 | case *actor.Stopped: |
| 61 | log.Warn("[p2p]actor stopped") |
| 62 | case *actor.Started: |
| 63 | log.Debug("[p2p]actor started") |
| 64 | case *actor.Restart: |
| 65 | log.Warn("[p2p]actor restart") |
| 66 | case *StopServerReq: |
| 67 | this.handleStopServerReq(ctx, msg) |
| 68 | case *GetPortReq: |
| 69 | this.handleGetPortReq(ctx, msg) |
| 70 | case *GetVersionReq: |
| 71 | this.handleGetVersionReq(ctx, msg) |
| 72 | case *GetConnectionCntReq: |
| 73 | this.handleGetConnectionCntReq(ctx, msg) |
| 74 | case *GetMaxPeerBlockHeightReq: |
| 75 | this.handleGetMaxPeerBlockHeightReq(ctx, msg) |
| 76 | case *GetIdReq: |
| 77 | this.handleGetIDReq(ctx, msg) |
| 78 | case *GetConnectionStateReq: |
| 79 | this.handleGetConnectionStateReq(ctx, msg) |
| 80 | case *GetTimeReq: |
| 81 | this.handleGetTimeReq(ctx, msg) |
| 82 | case *GetNeighborAddrsReq: |
| 83 | this.handleGetNeighborAddrsReq(ctx, msg) |
| 84 | case *GetRelayStateReq: |
| 85 | this.handleGetRelayStateReq(ctx, msg) |
| 86 | case *GetNodeTypeReq: |
| 87 | this.handleGetNodeTypeReq(ctx, msg) |
| 88 | case *TransmitConsensusMsgReq: |
| 89 | this.handleTransmitConsensusMsgReq(ctx, msg) |
| 90 | case *common.AppendPeerID: |
| 91 | this.server.OnAddNode(msg.ID) |
| 92 | case *common.RemovePeerID: |
| 93 | this.server.OnDelNode(msg.ID) |
| 94 | case *common.AppendHeaders: |
| 95 | this.server.OnHeaderReceive(msg.FromID, msg.Headers) |
| 96 | case *common.AppendBlock: |
| 97 | this.server.OnBlockReceive(msg.FromID, msg.BlockSize, msg.Block, msg.MerkleRoot) |
| 98 | default: |
| 99 | err := this.server.Xmit(ctx.Message()) |
| 100 | if nil != err { |
| 101 | log.Warn("[p2p]error xmit message ", err.Error(), reflect.TypeOf(ctx.Message())) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | //stop handler |
| 107 | func (this *P2PActor) handleStopServerReq(ctx actor.Context, req *StopServerReq) { |
nothing calls this directly
no test coverage detected