proto

package
v0.0.0-...-f4f9239 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion  = 1
	MaxMessagesCount = 0xffffffff
)
View Source
const CommandLength = 4
View Source
const MaxPacketSize uint32 = 8192

Variables

View Source
var (
	ErrCounterOverflow = errors.New("message counter overflow")
	ErrLowCounter      = errors.New("message counter is too low")
	ErrShortMessage    = errors.New("message is too short")
	ErrAuth            = errors.New("authentication failed")
	ErrIVGen           = errors.New("failed to generate initialization vector")
)
View Source
var (
	ErrParseDHState = errors.New("failed to parse second user's diffie-hellman state")
	ErrParseHalfKey = errors.New("failed to parse second user's halfkey")
	ErrWeakHalfkey  = errors.New("weak halfkey from second user")

	ErrShortQ = errWeakDHState("q constant size lower than 256 bits")
	ErrShortP = errWeakDHState("p constant size lower than 2048 bits")
	ErrWrongG = errWeakDHState("g^q (modp) doesn't equal 1")
)
View Source
var ErrLongPacket = errors.New("packet is too long")
View Source
var (
	ErrShortCommand = errors.New("command is too short")
)
View Source
var ManagerCommands = managerCommands()
View Source
var PeerCommands = peerCommands()

Functions

This section is empty.

Types

type Command

type Command [CommandLength]byte

type CommandParser

type CommandParser struct {
	// contains filtered or unexported fields
}

func CreateCommandParser

func CreateCommandParser(typeChecker func(interface{}) bool) *CommandParser

func (*CommandParser) AddCommand

func (parser *CommandParser) AddCommand(cmd Command, handler interface{})

func (*CommandParser) CommandLoop

func (parser *CommandParser) CommandLoop(rw PackageReadWriter, execute func(interface{}, []byte) error)

func (*CommandParser) GetHandler

func (parser *CommandParser) GetHandler(data []byte) (interface{}, []byte, error)

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func CreateConn

func CreateConn(conn net.Conn) *Conn

func Dial

func Dial(network, address string) (*Conn, error)

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) ReadPackage

func (c *Conn) ReadPackage() ([]byte, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) WritePackage

func (c *Conn) WritePackage(data []byte) (int, error)

type CryptoState

type CryptoState struct {
	SendEnc    cipher.Block
	RecEnc     cipher.Block
	SendAuth   hash.Hash
	RecAuth    hash.Hash
	MsgSendCtr uint32
	MsgRecCtr  uint32
}

func InitCryptoState

func InitCryptoState(key []byte, isUserA bool) *CryptoState

func (*CryptoState) AuthAndEncrypt

func (cs *CryptoState) AuthAndEncrypt(data []byte) ([]byte, error)

func (*CryptoState) DecryptAndAuth

func (cs *CryptoState) DecryptAndAuth(data []byte) ([]byte, error)

func (*CryptoState) RecAuthMessage

func (cs *CryptoState) RecAuthMessage(data []byte) []byte

func (*CryptoState) SendAuthMessage

func (cs *CryptoState) SendAuthMessage(data []byte) []byte

type DHState

type DHState struct {
	G, Q, P *big.Int
}

func InitDHState

func InitDHState() (*DHState, error)

func (*DHState) ActiveDHExchange

func (dh *DHState) ActiveDHExchange(conn *Conn) ([]byte, error)

func (*DHState) CheckDHState

func (dh *DHState) CheckDHState() error

func (*DHState) CheckHalfkey

func (dh *DHState) CheckHalfkey(halfkey *big.Int) bool

func (*DHState) PassiveDHExchange

func (dh *DHState) PassiveDHExchange(conn *Conn) ([]byte, error)

type File

type File struct {
	Name string
	Data []byte
}

type Host

type Host struct {
	Login    string
	Addr     string
	DifHel   *DHState         `json:"-"`
	Peers    map[string]*Peer `json:"-"`
	Commands *CommandParser   `json:"-"`
	Msg      chan string      `json:"-"`
	Quit     chan bool        `json:"-"`
}

func (*Host) AcceptPeer

func (host *Host) AcceptPeer(conn *Conn) (*Peer, error)

func (*Host) DialPeer

func (host *Host) DialPeer(conn *Conn) (*Peer, error)

func (*Host) Disconnect

func (host *Host) Disconnect()

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

func CreateListener

func CreateListener(listener net.Listener) *Listener

func Listen

func Listen(network, address string) (*Listener, error)

func (*Listener) Accept

func (ln *Listener) Accept() (*Conn, error)

func (*Listener) Addr

func (ln *Listener) Addr() net.Addr

func (*Listener) Close

func (ln *Listener) Close() error

type Manager

type Manager struct {
	Conn     *Conn
	Peer     *Peer
	Commands *CommandParser
}

func (*Manager) SendMessage

func (manager *Manager) SendMessage(msg []byte) error

type ManagerHandler

type ManagerHandler func(*Host, *Manager, []byte) error

type Message

type Message struct {
	Type  string
	Login string
	Addr  string
	Data  string
}

type PackageReadWriter

type PackageReadWriter interface {
	ReadPackage() ([]byte, error)
	WritePackage([]byte) (int, error)
}

type Peer

type Peer struct {
	Login  string
	Addr   string
	DifHel *DHState     `json:"-"`
	Crypto *CryptoState `json:"-"`
	Conn   *Conn        `json:"-"`
}

func (*Peer) Close

func (p *Peer) Close()

func (*Peer) ReadPackage

func (p *Peer) ReadPackage() ([]byte, error)

func (*Peer) WritePackage

func (p *Peer) WritePackage(buf []byte) (int, error)

type PeerHandler

type PeerHandler func(*Host, *Peer, []byte) error

Jump to

Keyboard shortcuts

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