Documentation

Overview

    Package agent-tcp implements a TCP based agent to participate in consensus Challenge-Response scheme has been adopted to do interactive authentication

    Index

    Constants

    View Source
    const (
    	// Frame format:
    	// |MessageLength(4bytes)| Message(MessageLength) ... |
    	MessageLength = 4
    
    	// Message max length(32MB)
    	MaxMessageLength = 32 * 1024 * 1024
    )

    Variables

    View Source
    var (
    	ErrLocalKeyAuthInit             = errors.New("incorrect state for local KeyAuthInitmessage")
    	ErrKeyNotOnCurve                = errors.New("the public key is not on curve")
    	ErrPeerKeyAuthInit              = errors.New("incorrect state for peer KeyAuthInit message")
    	ErrPeerKeyAuthChallenge         = errors.New("incorrect state for peer KeyAuthChallenge message")
    	ErrPeerKeyAuthChallengeResponse = errors.New("incorrect state for peer KeyAuthChallengeResponse message")
    	ErrPeerAuthenticatedFailed      = errors.New("public key authentication failed for peer")
    	ErrMessageLengthExceed          = errors.New("message size exceeded maximum")
    )
    View Source
    var (
    	ErrInvalidLengthGossip        = fmt.Errorf("proto: negative length found during unmarshaling")
    	ErrIntOverflowGossip          = fmt.Errorf("proto: integer overflow")
    	ErrUnexpectedEndOfGroupGossip = fmt.Errorf("proto: unexpected end of group")
    )
    View Source
    var CommandType_name = map[int32]string{
    	0: "NOP",
    	1: "KEY_AUTH_INIT",
    	2: "KEY_AUTH_CHALLENGE",
    	3: "KEY_AUTH_CHALLENGE_REPLY",
    	4: "CONSENSUS",
    }
    View Source
    var CommandType_value = map[string]int32{
    	"NOP":                      0,
    	"KEY_AUTH_INIT":            1,
    	"KEY_AUTH_CHALLENGE":       2,
    	"KEY_AUTH_CHALLENGE_REPLY": 3,
    	"CONSENSUS":                4,
    }

    Functions

    func ECDH

    func ECDH(publicKey *ecdsa.PublicKey, key *ecdsa.PrivateKey) *big.Int

    Types

    type CommandType

    type CommandType int32

      CommandType defines supported commands

      const (
      	CommandType_NOP                      CommandType = 0
      	CommandType_KEY_AUTH_INIT            CommandType = 1
      	CommandType_KEY_AUTH_CHALLENGE       CommandType = 2
      	CommandType_KEY_AUTH_CHALLENGE_REPLY CommandType = 3
      	CommandType_CONSENSUS                CommandType = 4
      )

      func (CommandType) EnumDescriptor

      func (CommandType) EnumDescriptor() ([]byte, []int)

      func (CommandType) String

      func (x CommandType) String() string

      type Gossip

      type Gossip struct {
      	Command              CommandType `protobuf:"varint,1,opt,name=Command,proto3,enum=agent.CommandType" json:"Command,omitempty"`
      	Message              []byte      `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"`
      	XXX_NoUnkeyedLiteral struct{}    `json:"-"`
      	XXX_unrecognized     []byte      `json:"-"`
      	XXX_sizecache        int32       `json:"-"`
      }

        Gossip defines a stream based protocol

        func (*Gossip) Descriptor

        func (*Gossip) Descriptor() ([]byte, []int)

        func (*Gossip) GetCommand

        func (m *Gossip) GetCommand() CommandType

        func (*Gossip) GetMessage

        func (m *Gossip) GetMessage() []byte

        func (*Gossip) Marshal

        func (m *Gossip) Marshal() (dAtA []byte, err error)

        func (*Gossip) MarshalTo

        func (m *Gossip) MarshalTo(dAtA []byte) (int, error)

        func (*Gossip) MarshalToSizedBuffer

        func (m *Gossip) MarshalToSizedBuffer(dAtA []byte) (int, error)

        func (*Gossip) ProtoMessage

        func (*Gossip) ProtoMessage()

        func (*Gossip) Reset

        func (m *Gossip) Reset()

        func (*Gossip) Size

        func (m *Gossip) Size() (n int)

        func (*Gossip) String

        func (m *Gossip) String() string

        func (*Gossip) Unmarshal

        func (m *Gossip) Unmarshal(dAtA []byte) error

        func (*Gossip) XXX_DiscardUnknown

        func (m *Gossip) XXX_DiscardUnknown()

        func (*Gossip) XXX_Marshal

        func (m *Gossip) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

        func (*Gossip) XXX_Merge

        func (m *Gossip) XXX_Merge(src proto.Message)

        func (*Gossip) XXX_Size

        func (m *Gossip) XXX_Size() int

        func (*Gossip) XXX_Unmarshal

        func (m *Gossip) XXX_Unmarshal(b []byte) error

        type KeyAuthChallenge

        type KeyAuthChallenge struct {
        	// server ephermal publickey for client authentication
        	X []byte `protobuf:"bytes,1,opt,name=X,proto3" json:"X,omitempty"`
        	Y []byte `protobuf:"bytes,2,opt,name=Y,proto3" json:"Y,omitempty"`
        	// the challenge message, the peer can create the correct HMAC with this message
        	Challenge            []byte   `protobuf:"bytes,3,opt,name=Challenge,proto3" json:"Challenge,omitempty"`
        	XXX_NoUnkeyedLiteral struct{} `json:"-"`
        	XXX_unrecognized     []byte   `json:"-"`
        	XXX_sizecache        int32    `json:"-"`
        }

        func (*KeyAuthChallenge) Descriptor

        func (*KeyAuthChallenge) Descriptor() ([]byte, []int)

        func (*KeyAuthChallenge) GetChallenge

        func (m *KeyAuthChallenge) GetChallenge() []byte

        func (*KeyAuthChallenge) GetX

        func (m *KeyAuthChallenge) GetX() []byte

        func (*KeyAuthChallenge) GetY

        func (m *KeyAuthChallenge) GetY() []byte

        func (*KeyAuthChallenge) Marshal

        func (m *KeyAuthChallenge) Marshal() (dAtA []byte, err error)

        func (*KeyAuthChallenge) MarshalTo

        func (m *KeyAuthChallenge) MarshalTo(dAtA []byte) (int, error)

        func (*KeyAuthChallenge) MarshalToSizedBuffer

        func (m *KeyAuthChallenge) MarshalToSizedBuffer(dAtA []byte) (int, error)

        func (*KeyAuthChallenge) ProtoMessage

        func (*KeyAuthChallenge) ProtoMessage()

        func (*KeyAuthChallenge) Reset

        func (m *KeyAuthChallenge) Reset()

        func (*KeyAuthChallenge) Size

        func (m *KeyAuthChallenge) Size() (n int)

        func (*KeyAuthChallenge) String

        func (m *KeyAuthChallenge) String() string

        func (*KeyAuthChallenge) Unmarshal

        func (m *KeyAuthChallenge) Unmarshal(dAtA []byte) error

        func (*KeyAuthChallenge) XXX_DiscardUnknown

        func (m *KeyAuthChallenge) XXX_DiscardUnknown()

        func (*KeyAuthChallenge) XXX_Marshal

        func (m *KeyAuthChallenge) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

        func (*KeyAuthChallenge) XXX_Merge

        func (m *KeyAuthChallenge) XXX_Merge(src proto.Message)

        func (*KeyAuthChallenge) XXX_Size

        func (m *KeyAuthChallenge) XXX_Size() int

        func (*KeyAuthChallenge) XXX_Unmarshal

        func (m *KeyAuthChallenge) XXX_Unmarshal(b []byte) error

        type KeyAuthChallengeReply

        type KeyAuthChallengeReply struct {
        	HMAC                 []byte   `protobuf:"bytes,1,opt,name=HMAC,proto3" json:"HMAC,omitempty"`
        	XXX_NoUnkeyedLiteral struct{} `json:"-"`
        	XXX_unrecognized     []byte   `json:"-"`
        	XXX_sizecache        int32    `json:"-"`
        }

        func (*KeyAuthChallengeReply) Descriptor

        func (*KeyAuthChallengeReply) Descriptor() ([]byte, []int)

        func (*KeyAuthChallengeReply) GetHMAC

        func (m *KeyAuthChallengeReply) GetHMAC() []byte

        func (*KeyAuthChallengeReply) Marshal

        func (m *KeyAuthChallengeReply) Marshal() (dAtA []byte, err error)

        func (*KeyAuthChallengeReply) MarshalTo

        func (m *KeyAuthChallengeReply) MarshalTo(dAtA []byte) (int, error)

        func (*KeyAuthChallengeReply) MarshalToSizedBuffer

        func (m *KeyAuthChallengeReply) MarshalToSizedBuffer(dAtA []byte) (int, error)

        func (*KeyAuthChallengeReply) ProtoMessage

        func (*KeyAuthChallengeReply) ProtoMessage()

        func (*KeyAuthChallengeReply) Reset

        func (m *KeyAuthChallengeReply) Reset()

        func (*KeyAuthChallengeReply) Size

        func (m *KeyAuthChallengeReply) Size() (n int)

        func (*KeyAuthChallengeReply) String

        func (m *KeyAuthChallengeReply) String() string

        func (*KeyAuthChallengeReply) Unmarshal

        func (m *KeyAuthChallengeReply) Unmarshal(dAtA []byte) error

        func (*KeyAuthChallengeReply) XXX_DiscardUnknown

        func (m *KeyAuthChallengeReply) XXX_DiscardUnknown()

        func (*KeyAuthChallengeReply) XXX_Marshal

        func (m *KeyAuthChallengeReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

        func (*KeyAuthChallengeReply) XXX_Merge

        func (m *KeyAuthChallengeReply) XXX_Merge(src proto.Message)

        func (*KeyAuthChallengeReply) XXX_Size

        func (m *KeyAuthChallengeReply) XXX_Size() int

        func (*KeyAuthChallengeReply) XXX_Unmarshal

        func (m *KeyAuthChallengeReply) XXX_Unmarshal(b []byte) error

        type KeyAuthInit

        type KeyAuthInit struct {
        	// client public key
        	X                    []byte   `protobuf:"bytes,1,opt,name=X,proto3" json:"X,omitempty"`
        	Y                    []byte   `protobuf:"bytes,2,opt,name=Y,proto3" json:"Y,omitempty"`
        	XXX_NoUnkeyedLiteral struct{} `json:"-"`
        	XXX_unrecognized     []byte   `json:"-"`
        	XXX_sizecache        int32    `json:"-"`
        }

        func (*KeyAuthInit) Descriptor

        func (*KeyAuthInit) Descriptor() ([]byte, []int)

        func (*KeyAuthInit) GetX

        func (m *KeyAuthInit) GetX() []byte

        func (*KeyAuthInit) GetY

        func (m *KeyAuthInit) GetY() []byte

        func (*KeyAuthInit) Marshal

        func (m *KeyAuthInit) Marshal() (dAtA []byte, err error)

        func (*KeyAuthInit) MarshalTo

        func (m *KeyAuthInit) MarshalTo(dAtA []byte) (int, error)

        func (*KeyAuthInit) MarshalToSizedBuffer

        func (m *KeyAuthInit) MarshalToSizedBuffer(dAtA []byte) (int, error)

        func (*KeyAuthInit) ProtoMessage

        func (*KeyAuthInit) ProtoMessage()

        func (*KeyAuthInit) Reset

        func (m *KeyAuthInit) Reset()

        func (*KeyAuthInit) Size

        func (m *KeyAuthInit) Size() (n int)

        func (*KeyAuthInit) String

        func (m *KeyAuthInit) String() string

        func (*KeyAuthInit) Unmarshal

        func (m *KeyAuthInit) Unmarshal(dAtA []byte) error

        func (*KeyAuthInit) XXX_DiscardUnknown

        func (m *KeyAuthInit) XXX_DiscardUnknown()

        func (*KeyAuthInit) XXX_Marshal

        func (m *KeyAuthInit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

        func (*KeyAuthInit) XXX_Merge

        func (m *KeyAuthInit) XXX_Merge(src proto.Message)

        func (*KeyAuthInit) XXX_Size

        func (m *KeyAuthInit) XXX_Size() int

        func (*KeyAuthInit) XXX_Unmarshal

        func (m *KeyAuthInit) XXX_Unmarshal(b []byte) error

        type TCPAgent

        type TCPAgent struct {
        	sync.Mutex // fields lock
        	// contains filtered or unexported fields
        }

          A TCPAgent binds consensus core to a TCPAgent object, which may have multiple TCPPeer

          func NewTCPAgent

          func NewTCPAgent(consensus *bdls.Consensus, privateKey *ecdsa.PrivateKey) *TCPAgent

            NewTCPAgent initiate a TCPAgent which talks consensus protocol with peers

            func (*TCPAgent) AddPeer

            func (agent *TCPAgent) AddPeer(p *TCPPeer) bool

              AddPeer adds a peer to this agent

              func (*TCPAgent) Close

              func (agent *TCPAgent) Close()

                Close stops all activities on this agent

                func (*TCPAgent) GetLatestState

                func (agent *TCPAgent) GetLatestState() (height uint64, round uint64, data bdls.State)

                  GetLatestState returns latest state

                  func (*TCPAgent) Propose

                  func (agent *TCPAgent) Propose(s bdls.State)

                    Propose a state, awaiting to be finalized at next height.

                    func (*TCPAgent) RemovePeer

                    func (agent *TCPAgent) RemovePeer(p *TCPPeer) bool

                      RemovePeer removes a TCPPeer from this agent

                      func (*TCPAgent) Update

                      func (agent *TCPAgent) Update()

                        Update is the consensus updater

                        type TCPPeer

                        type TCPPeer struct {
                        
                        	// mutex for all fields
                        	sync.Mutex
                        	// contains filtered or unexported fields
                        }

                          TCPPeer represents a peer(endpoint) related to a tcp connection

                          func NewTCPPeer

                          func NewTCPPeer(conn net.Conn, agent *TCPAgent) *TCPPeer

                            NewTCPPeer creates a TCPPeer with protocol over this connection

                            func (*TCPPeer) Close

                            func (p *TCPPeer) Close()

                              Close terminates connection to this peer

                              func (*TCPPeer) GetPublicKey

                              func (p *TCPPeer) GetPublicKey() *ecdsa.PublicKey

                                RemoteAddr implements PeerInterface, GetPublicKey returns peer's public key, returns nil if peer's has not authenticated it's public-key

                                func (*TCPPeer) InitiatePublicKeyAuthentication

                                func (p *TCPPeer) InitiatePublicKeyAuthentication() error

                                  InitiatePublicKeyAuthentication will initate a procedure to convince the other peer to trust my ownership of public key

                                  func (*TCPPeer) RemoteAddr

                                  func (p *TCPPeer) RemoteAddr() net.Addr

                                    RemoteAddr implements PeerInterface, returns peer's address as connection identity

                                    func (*TCPPeer) Send

                                    func (p *TCPPeer) Send(out []byte) error

                                      Send implements PeerInterface, to send message to this peer