agent

package
v1.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2020 License: BSD-3-Clause Imports: 19 Imported by: 0

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 added in v1.1.0

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

Types

type CommandType added in v1.1.0

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 added in v1.1.0

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

func (CommandType) String added in v1.1.0

func (x CommandType) String() string

type Gossip added in v1.1.0

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 added in v1.1.0

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

func (*Gossip) GetCommand added in v1.1.0

func (m *Gossip) GetCommand() CommandType

func (*Gossip) GetMessage added in v1.1.0

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

func (*Gossip) Marshal added in v1.1.0

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

func (*Gossip) MarshalTo added in v1.1.0

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

func (*Gossip) MarshalToSizedBuffer added in v1.1.0

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

func (*Gossip) ProtoMessage added in v1.1.0

func (*Gossip) ProtoMessage()

func (*Gossip) Reset added in v1.1.0

func (m *Gossip) Reset()

func (*Gossip) Size added in v1.1.0

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

func (*Gossip) String added in v1.1.0

func (m *Gossip) String() string

func (*Gossip) Unmarshal added in v1.1.0

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

func (*Gossip) XXX_DiscardUnknown added in v1.1.0

func (m *Gossip) XXX_DiscardUnknown()

func (*Gossip) XXX_Marshal added in v1.1.0

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

func (*Gossip) XXX_Merge added in v1.1.0

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

func (*Gossip) XXX_Size added in v1.1.0

func (m *Gossip) XXX_Size() int

func (*Gossip) XXX_Unmarshal added in v1.1.0

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

type KeyAuthChallenge added in v1.1.0

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 added in v1.1.0

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

func (*KeyAuthChallenge) GetChallenge added in v1.1.0

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

func (*KeyAuthChallenge) GetX added in v1.1.0

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

func (*KeyAuthChallenge) GetY added in v1.1.0

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

func (*KeyAuthChallenge) Marshal added in v1.1.0

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

func (*KeyAuthChallenge) MarshalTo added in v1.1.0

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

func (*KeyAuthChallenge) MarshalToSizedBuffer added in v1.1.0

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

func (*KeyAuthChallenge) ProtoMessage added in v1.1.0

func (*KeyAuthChallenge) ProtoMessage()

func (*KeyAuthChallenge) Reset added in v1.1.0

func (m *KeyAuthChallenge) Reset()

func (*KeyAuthChallenge) Size added in v1.1.0

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

func (*KeyAuthChallenge) String added in v1.1.0

func (m *KeyAuthChallenge) String() string

func (*KeyAuthChallenge) Unmarshal added in v1.1.0

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

func (*KeyAuthChallenge) XXX_DiscardUnknown added in v1.1.0

func (m *KeyAuthChallenge) XXX_DiscardUnknown()

func (*KeyAuthChallenge) XXX_Marshal added in v1.1.0

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

func (*KeyAuthChallenge) XXX_Merge added in v1.1.0

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

func (*KeyAuthChallenge) XXX_Size added in v1.1.0

func (m *KeyAuthChallenge) XXX_Size() int

func (*KeyAuthChallenge) XXX_Unmarshal added in v1.1.0

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

type KeyAuthChallengeReply added in v1.1.0

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 added in v1.1.0

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

func (*KeyAuthChallengeReply) GetHMAC added in v1.1.0

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

func (*KeyAuthChallengeReply) Marshal added in v1.1.0

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

func (*KeyAuthChallengeReply) MarshalTo added in v1.1.0

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

func (*KeyAuthChallengeReply) MarshalToSizedBuffer added in v1.1.0

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

func (*KeyAuthChallengeReply) ProtoMessage added in v1.1.0

func (*KeyAuthChallengeReply) ProtoMessage()

func (*KeyAuthChallengeReply) Reset added in v1.1.0

func (m *KeyAuthChallengeReply) Reset()

func (*KeyAuthChallengeReply) Size added in v1.1.0

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

func (*KeyAuthChallengeReply) String added in v1.1.0

func (m *KeyAuthChallengeReply) String() string

func (*KeyAuthChallengeReply) Unmarshal added in v1.1.0

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

func (*KeyAuthChallengeReply) XXX_DiscardUnknown added in v1.1.0

func (m *KeyAuthChallengeReply) XXX_DiscardUnknown()

func (*KeyAuthChallengeReply) XXX_Marshal added in v1.1.0

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

func (*KeyAuthChallengeReply) XXX_Merge added in v1.1.0

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

func (*KeyAuthChallengeReply) XXX_Size added in v1.1.0

func (m *KeyAuthChallengeReply) XXX_Size() int

func (*KeyAuthChallengeReply) XXX_Unmarshal added in v1.1.0

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

type KeyAuthInit added in v1.1.0

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 added in v1.1.0

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

func (*KeyAuthInit) GetX added in v1.1.0

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

func (*KeyAuthInit) GetY added in v1.1.0

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

func (*KeyAuthInit) Marshal added in v1.1.0

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

func (*KeyAuthInit) MarshalTo added in v1.1.0

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

func (*KeyAuthInit) MarshalToSizedBuffer added in v1.1.0

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

func (*KeyAuthInit) ProtoMessage added in v1.1.0

func (*KeyAuthInit) ProtoMessage()

func (*KeyAuthInit) Reset added in v1.1.0

func (m *KeyAuthInit) Reset()

func (*KeyAuthInit) Size added in v1.1.0

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

func (*KeyAuthInit) String added in v1.1.0

func (m *KeyAuthInit) String() string

func (*KeyAuthInit) Unmarshal added in v1.1.0

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

func (*KeyAuthInit) XXX_DiscardUnknown added in v1.1.0

func (m *KeyAuthInit) XXX_DiscardUnknown()

func (*KeyAuthInit) XXX_Marshal added in v1.1.0

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

func (*KeyAuthInit) XXX_Merge added in v1.1.0

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

func (*KeyAuthInit) XXX_Size added in v1.1.0

func (m *KeyAuthInit) XXX_Size() int

func (*KeyAuthInit) XXX_Unmarshal added in v1.1.0

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

type TCPAgent added in v1.1.0

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 added in v1.1.0

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

NewTCPAgent initiate a TCPAgent which talks consensus protocol with peers

func (*TCPAgent) AddPeer added in v1.1.0

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

AddPeer adds a peer to this agent

func (*TCPAgent) Close added in v1.1.0

func (agent *TCPAgent) Close()

Close stops all activities on this agent

func (*TCPAgent) GetLatestState added in v1.1.0

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

GetLatestState returns latest state

func (*TCPAgent) Propose added in v1.1.0

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

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

func (*TCPAgent) RemovePeer added in v1.1.0

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

RemovePeer removes a TCPPeer from this agent

func (*TCPAgent) Update added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL