bdls: github.com/Sperax/bdls/agent-tcp Index | Files

package agent

import "github.com/Sperax/bdls/agent-tcp"

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

Index

Package Files

doc.go ecdh.go errors.go gossip.pb.go tcp_peer.go

Constants

const (
    // Frame format:
    // |MessageLength(4bytes)| Message(MessageLength) ... |
    MessageLength = 4

    // Message max length(32MB)
    MaxMessageLength = 32 * 1024 * 1024
)

Variables

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")
)
var (
    ErrInvalidLengthGossip        = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowGossip          = fmt.Errorf("proto: integer overflow")
    ErrUnexpectedEndOfGroupGossip = fmt.Errorf("proto: unexpected end of group")
)
var CommandType_name = map[int32]string{
    0:  "NOP",
    1:  "KEY_AUTH_INIT",
    2:  "KEY_AUTH_CHALLENGE",
    3:  "KEY_AUTH_CHALLENGE_REPLY",
    4:  "CONSENSUS",
}
var CommandType_value = map[string]int32{
    "NOP":                      0,
    "KEY_AUTH_INIT":            1,
    "KEY_AUTH_CHALLENGE":       2,
    "KEY_AUTH_CHALLENGE_REPLY": 3,
    "CONSENSUS":                4,
}

func ECDH Uses

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

type CommandType Uses

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 Uses

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

func (CommandType) String Uses

func (x CommandType) String() string

type Gossip Uses

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 Uses

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

func (*Gossip) GetCommand Uses

func (m *Gossip) GetCommand() CommandType

func (*Gossip) GetMessage Uses

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

func (*Gossip) Marshal Uses

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

func (*Gossip) MarshalTo Uses

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

func (*Gossip) MarshalToSizedBuffer Uses

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

func (*Gossip) ProtoMessage Uses

func (*Gossip) ProtoMessage()

func (*Gossip) Reset Uses

func (m *Gossip) Reset()

func (*Gossip) Size Uses

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

func (*Gossip) String Uses

func (m *Gossip) String() string

func (*Gossip) Unmarshal Uses

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

func (*Gossip) XXX_DiscardUnknown Uses

func (m *Gossip) XXX_DiscardUnknown()

func (*Gossip) XXX_Marshal Uses

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

func (*Gossip) XXX_Merge Uses

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

func (*Gossip) XXX_Size Uses

func (m *Gossip) XXX_Size() int

func (*Gossip) XXX_Unmarshal Uses

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

type KeyAuthChallenge Uses

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 Uses

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

func (*KeyAuthChallenge) GetChallenge Uses

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

func (*KeyAuthChallenge) GetX Uses

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

func (*KeyAuthChallenge) GetY Uses

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

func (*KeyAuthChallenge) Marshal Uses

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

func (*KeyAuthChallenge) MarshalTo Uses

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

func (*KeyAuthChallenge) MarshalToSizedBuffer Uses

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

func (*KeyAuthChallenge) ProtoMessage Uses

func (*KeyAuthChallenge) ProtoMessage()

func (*KeyAuthChallenge) Reset Uses

func (m *KeyAuthChallenge) Reset()

func (*KeyAuthChallenge) Size Uses

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

func (*KeyAuthChallenge) String Uses

func (m *KeyAuthChallenge) String() string

func (*KeyAuthChallenge) Unmarshal Uses

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

func (*KeyAuthChallenge) XXX_DiscardUnknown Uses

func (m *KeyAuthChallenge) XXX_DiscardUnknown()

func (*KeyAuthChallenge) XXX_Marshal Uses

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

func (*KeyAuthChallenge) XXX_Merge Uses

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

func (*KeyAuthChallenge) XXX_Size Uses

func (m *KeyAuthChallenge) XXX_Size() int

func (*KeyAuthChallenge) XXX_Unmarshal Uses

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

type KeyAuthChallengeReply Uses

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 Uses

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

func (*KeyAuthChallengeReply) GetHMAC Uses

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

func (*KeyAuthChallengeReply) Marshal Uses

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

func (*KeyAuthChallengeReply) MarshalTo Uses

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

func (*KeyAuthChallengeReply) MarshalToSizedBuffer Uses

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

func (*KeyAuthChallengeReply) ProtoMessage Uses

func (*KeyAuthChallengeReply) ProtoMessage()

func (*KeyAuthChallengeReply) Reset Uses

func (m *KeyAuthChallengeReply) Reset()

func (*KeyAuthChallengeReply) Size Uses

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

func (*KeyAuthChallengeReply) String Uses

func (m *KeyAuthChallengeReply) String() string

func (*KeyAuthChallengeReply) Unmarshal Uses

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

func (*KeyAuthChallengeReply) XXX_DiscardUnknown Uses

func (m *KeyAuthChallengeReply) XXX_DiscardUnknown()

func (*KeyAuthChallengeReply) XXX_Marshal Uses

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

func (*KeyAuthChallengeReply) XXX_Merge Uses

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

func (*KeyAuthChallengeReply) XXX_Size Uses

func (m *KeyAuthChallengeReply) XXX_Size() int

func (*KeyAuthChallengeReply) XXX_Unmarshal Uses

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

type KeyAuthInit Uses

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 Uses

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

func (*KeyAuthInit) GetX Uses

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

func (*KeyAuthInit) GetY Uses

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

func (*KeyAuthInit) Marshal Uses

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

func (*KeyAuthInit) MarshalTo Uses

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

func (*KeyAuthInit) MarshalToSizedBuffer Uses

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

func (*KeyAuthInit) ProtoMessage Uses

func (*KeyAuthInit) ProtoMessage()

func (*KeyAuthInit) Reset Uses

func (m *KeyAuthInit) Reset()

func (*KeyAuthInit) Size Uses

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

func (*KeyAuthInit) String Uses

func (m *KeyAuthInit) String() string

func (*KeyAuthInit) Unmarshal Uses

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

func (*KeyAuthInit) XXX_DiscardUnknown Uses

func (m *KeyAuthInit) XXX_DiscardUnknown()

func (*KeyAuthInit) XXX_Marshal Uses

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

func (*KeyAuthInit) XXX_Merge Uses

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

func (*KeyAuthInit) XXX_Size Uses

func (m *KeyAuthInit) XXX_Size() int

func (*KeyAuthInit) XXX_Unmarshal Uses

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

type TCPAgent Uses

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 Uses

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

NewTCPAgent initiate a TCPAgent which talks consensus protocol with peers

func (*TCPAgent) AddPeer Uses

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

AddPeer adds a peer to this agent

func (*TCPAgent) Close Uses

func (agent *TCPAgent) Close()

Close stops all activities on this agent

func (*TCPAgent) GetLatestState Uses

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

GetLatestState returns latest state

func (*TCPAgent) Propose Uses

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

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

func (*TCPAgent) RemovePeer Uses

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

RemovePeer removes a TCPPeer from this agent

func (*TCPAgent) Update Uses

func (agent *TCPAgent) Update()

Update is the consensus updater

type TCPPeer Uses

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 Uses

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

NewTCPPeer creates a TCPPeer with protocol over this connection

func (*TCPPeer) Close Uses

func (p *TCPPeer) Close()

Close terminates connection to this peer

func (*TCPPeer) GetPublicKey Uses

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 Uses

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 Uses

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

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

func (*TCPPeer) Send Uses

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

Send implements PeerInterface, to send message to this peer

Package agent imports 19 packages (graph). Updated 2020-09-19. Refresh now. Tools for package owners.