github.com/annchain/OG@v0.0.9/og/message_archive/message_type.go (about)

     1  // Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package message_archive
    16  
    17  import (
    18  	"fmt"
    19  	types2 "github.com/annchain/OG/arefactor/og/types"
    20  	"github.com/annchain/OG/consensus/bft"
    21  	"github.com/annchain/OG/og/types"
    22  	"github.com/annchain/OG/og/types/archive"
    23  )
    24  
    25  //go:generate msgp
    26  
    27  //global msg counter , generate global msg request id
    28  var MsgCounter *MessageCounter
    29  
    30  type SendingType uint8
    31  
    32  const (
    33  	SendingTypeBroadcast SendingType = iota
    34  	SendingTypeMulticast
    35  	SendingTypeMulticastToSource
    36  	SendingTypeBroacastWithFilter
    37  	SendingTypeBroacastWithLink
    38  )
    39  
    40  //func (mt BinaryMessageType) IsValid() bool {
    41  //	if mt >= MessageTypeOg02Length {
    42  //		return false
    43  //	}
    44  //	return true
    45  //}
    46  
    47  func (m BinaryMessageType) GetMsg() types.Message {
    48  	var message types.Message
    49  	switch m {
    50  	case MessageTypeNewTx:
    51  		message = &archive.MessageNewTx{}
    52  	case MessageTypeNewSequencer:
    53  		message = &archive.MessageNewSequencer{}
    54  	case MessageTypeGetMsg:
    55  		message = &archive.MessageGetMsg{}
    56  	case MessageTypeControl:
    57  		message = &archive.MessageControl{}
    58  	case MessageTypeCampaign:
    59  		message = &types.MessageCampaign{}
    60  	case MessageTypeTermChange:
    61  		message = &types.MessageTermChange{}
    62  	//case MessageTypeConsensusDkgDeal:
    63  	//	message = &types.MessageConsensusDkgDeal{}
    64  	//case MessageTypeConsensusDkgDealResponse:
    65  	//	message = &types.MessageConsensusDkgDealResponse{}
    66  	//case MessageTypeConsensusDkgSigSets:
    67  	//	message = &types.MessageConsensusDkgSigSets{}
    68  	//case MessageTypeConsensusDkgGenesisPublicKey:
    69  	//	message = &types.MessageConsensusDkgGenesisPublicKey{}
    70  
    71  	case MessageTypeTermChangeResponse:
    72  		message = &types.MessageTermChangeResponse{}
    73  	case MessageTypeTermChangeRequest:
    74  		message = &types.MessageTermChangeRequest{}
    75  
    76  	case MessageTypeArchive:
    77  		message = &types.MessageNewArchive{}
    78  	case MessageTypeActionTX:
    79  		message = &archive.MessageNewActionTx{}
    80  
    81  	//case MessageTypeProposal:
    82  	//	message = &bft.BftMessageProposal{
    83  	//		Value: &bft.SequencerProposal{},
    84  	//	}
    85  	//case MessageTypePreVote:
    86  	//	message = &bft.BftMessagePreVote{}
    87  	//case MessageTypePreCommit:
    88  	//	message = &bft.BftMessagePreCommit{}
    89  	case MessageTypeNewTxs:
    90  		message = &archive.MessageNewTxs{}
    91  	case MessageTypeSequencerHeader:
    92  		message = &archive.MessageSequencerHeader{}
    93  
    94  	case MessageTypeBodiesRequest:
    95  		message = &archive.MessageBodiesRequest{}
    96  	case MessageTypeBodiesResponse:
    97  		message = &archive.MessageBodiesResponse{}
    98  
    99  	case MessageTypeTxsRequest:
   100  		message = &archive.MessageTxsRequest{}
   101  	case MessageTypeTxsResponse:
   102  		message = &archive.MessageTxsResponse{}
   103  	case MessageTypeHeaderRequest:
   104  		message = &archive.MessageHeaderRequest{}
   105  	case MessageTypeHeaderResponse:
   106  		message = &archive.MessageHeaderResponse{}
   107  	case MessageTypeDuplicate:
   108  		var dup archive.MessageDuplicate
   109  		message = &dup
   110  	case MessageTypePing:
   111  		message = &archive.MessagePing{}
   112  	case MessageTypePong:
   113  		message = &archive.MessagePong{}
   114  	case MessageTypeFetchByHashRequest:
   115  		message = &archive.MessageSyncRequest{}
   116  	case MessageTypeFetchByHashResponse:
   117  		message = &archive.MessageSyncResponse{}
   118  	default:
   119  		return nil
   120  	}
   121  	return message
   122  }
   123  
   124  
   125  //msgp:tuple SequencerProposal
   126  type SequencerProposal struct {
   127  	types.Sequencer
   128  }
   129  
   130  func (s *SequencerProposal) String() string {
   131  	return fmt.Sprintf("seqProposal") + s.Sequencer.String()
   132  }
   133  
   134  func (s SequencerProposal) Equal(o bft.Proposal) bool {
   135  	v, ok := o.(*SequencerProposal)
   136  	if !ok || v == nil {
   137  		return false
   138  	}
   139  	return s.GetHash() == v.GetHash()
   140  }
   141  
   142  func (s SequencerProposal) GetId() *types2.Hash {
   143  	//should copy ?
   144  	var hash types2.Hash
   145  	hash.MustSetBytes(s.GetHash().ToBytes(), types2.PaddingNone)
   146  	return &hash
   147  }
   148  
   149  func (s SequencerProposal) Copy() bft.Proposal {
   150  	var r SequencerProposal
   151  	r = s
   152  	return &r
   153  }
   154