channel

package
v0.5.32 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerMinKeySize = 512
	ServerKeySize    = 512

	ClientMinKeySize = 128
	ClientKeySize    = 256
)

Variables

View Source
var ErrKeyExchange = errors.New("invalid key exchange")

Functions

func JSON

func JSON(r io.Reader, data interface{}) (io.Reader, error)

Types

type Batch

type Batch struct {
	Filter ClientFilter
	Msg    Msg
}

type BinaryHistory

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

func NewBinaryHistory

func NewBinaryHistory(
	max int,
	appendOnlyFile string,
	current DecoderVersion,
	dec map[DecoderVersion]Decoder,
) (*BinaryHistory, error)

func (*BinaryHistory) Add

func (g *BinaryHistory) Add(d Msg)

func (*BinaryHistory) DecodeAppendFile

func (g *BinaryHistory) DecodeAppendFile(r io.Reader, cb func(Msg)) error

func (*BinaryHistory) Each

func (g *BinaryHistory) Each(cb func(Msg) bool)

func (*BinaryHistory) Last

func (g *BinaryHistory) Last(n int, cb func(Msg) bool)

func (*BinaryHistory) Load

func (g *BinaryHistory) Load(file string) error

func (*BinaryHistory) NeedsSave

func (g *BinaryHistory) NeedsSave() bool

func (*BinaryHistory) Save

func (g *BinaryHistory) Save(file string) error

func (*BinaryHistory) StartAppend

func (g *BinaryHistory) StartAppend() error

func (*BinaryHistory) StopAppend

func (g *BinaryHistory) StopAppend()

type BinaryReader

type BinaryReader interface {
	Err() error

	Reader() io.Reader

	ReadUint(byte) uint64
	ReadUint8() uint8
	ReadUint16() uint16
	ReadUint32() uint32
	ReadUint64() uint64

	ReadBytes(byte) []byte
	ReadString(byte) string
}

type BinaryWriter

type BinaryWriter interface {
	Err() error

	Writer() io.Writer

	WriteUint(uint64, byte)
	WriteUint8(uint8)
	WriteUint16(uint16)
	WriteUint32(uint32)
	WriteUint64(uint64)

	WriteBytes([]byte, byte)
	WriteString(string, byte)
}

type BufferedWriteFlusher

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

func (*BufferedWriteFlusher) Flush

func (w *BufferedWriteFlusher) Flush() error

func (*BufferedWriteFlusher) Write

func (w *BufferedWriteFlusher) Write(b []byte) (int, error)

type Channel

type Channel interface {
	Register(name string, s Sender) error

	NeedsSave() bool
	Save(string) error
	Load(file string) error

	Run() error
	Close() error

	LimitReader() int64

	HandleBIN(Client, BinaryReader) error
	HandleJSON(Client, io.Reader) (io.Reader, error)
}

type ChannelMsg

type ChannelMsg struct {
	Data string `json:"d"`
	NoClose
}

func BinaryChannelMsg

func BinaryChannelMsg(r BinaryReader) (ChannelMsg, error)

func JSONChannelMsg

func JSONChannelMsg(r io.Reader) (ChannelMsg, io.Reader, error)

func (ChannelMsg) Binary

func (h ChannelMsg) Binary(w BinaryWriter) error

func (ChannelMsg) Equal

func (m ChannelMsg) Equal(Msg) bool

func (ChannelMsg) FromBinary

func (m ChannelMsg) FromBinary(r BinaryReader) (Msg, error)

func (ChannelMsg) FromJSON

func (m ChannelMsg) FromJSON(r io.Reader) (Msg, io.Reader, error)

func (ChannelMsg) JSON

func (h ChannelMsg) JSON(w io.Writer) error

type Client

type Client interface {
	Name() string
	Bot() bool
}

type ClientFilter

type ClientFilter struct {
	Client     Client
	Channel    string
	HasChannel []string
	To         []string
	NotTo      []string
}

func (ClientFilter) CheckChannels

func (f ClientFilter) CheckChannels(n []string) bool

func (ClientFilter) CheckIdentity

func (f ClientFilter) CheckIdentity(c Client) bool

func (ClientFilter) CheckIdentityAndName

func (f ClientFilter) CheckIdentityAndName(c Client) bool

func (ClientFilter) CheckName

func (f ClientFilter) CheckName(n string) bool

type ConnectionReason

type ConnectionReason byte
const (
	Connect ConnectionReason = iota
	Disconnect
)

type CryptoLabel

type CryptoLabel string
const (
	CryptoClientWrite    CryptoLabel = "write"
	CryptoClientRead     CryptoLabel = "read"
	CryptoClientMacWrite CryptoLabel = "mac-write"
	CryptoClientMacRead  CryptoLabel = "mac-read"

	CryptoServerWrite CryptoLabel = CryptoClientRead
	CryptoServerRead  CryptoLabel = CryptoClientWrite

	CryptoServerMacWrite CryptoLabel = CryptoClientMacRead
	CryptoServerMacRead  CryptoLabel = CryptoClientMacWrite
)

type Decoder

type Decoder = func(r BinaryReader) (Msg, error)

type DecoderVersion

type DecoderVersion string

type DeriveSecret

type DeriveSecret func(label CryptoLabel) []byte

func CommonSecret

func CommonSecret(c PubKeyMessage, s PubKeyServerMessage, serverPrivate *crypto.Key, size int) (DeriveSecret, error)

type DeriveSecret32

type DeriveSecret32 func(label CryptoLabel) [32]byte

func CommonSecret32

func CommonSecret32(c PubKeyMessage, s PubKeyServerMessage, serverPrivate *crypto.Key) (DeriveSecret32, error)

type EOF

type EOF struct {
	NilMsg
}

func BinaryMessage

func BinaryMessage(r BinaryReader) (EOF, error)

func JSONMessage

func JSONMessage(r io.Reader) (EOF, io.Reader, error)

func (EOF) FromBinary

func (m EOF) FromBinary(r BinaryReader) (Msg, error)

func (EOF) FromJSON

func (m EOF) FromJSON(r io.Reader) (Msg, io.Reader, error)

type FlushFlusher

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

func (*FlushFlusher) Flush

func (w *FlushFlusher) Flush() error

type Flusher

type Flusher interface {
	Flush() error
}

func NewFlushFlusher

func NewFlushFlusher(flushers ...Flusher) Flusher

type Hex

type Hex struct{}

func (Hex) DecodeString

func (h Hex) DecodeString(i string) ([]byte, error)

func (Hex) EncodeToString

func (h Hex) EncodeToString(i []byte) string

type IdentifyMsg

type IdentifyMsg struct {
	Data     string   `json:"d"`
	Channels []string `json:"c"`
	Version  string   `json:"v"`

	NeverEqual
	NoClose
}

func BinaryIdentifyMsg

func BinaryIdentifyMsg(r BinaryReader) (IdentifyMsg, error)

func JSONIdentifyMsg

func JSONIdentifyMsg(r io.Reader) (IdentifyMsg, io.Reader, error)

func (IdentifyMsg) Binary

func (h IdentifyMsg) Binary(w BinaryWriter) error

func (IdentifyMsg) FromBinary

func (m IdentifyMsg) FromBinary(r BinaryReader) (Msg, error)

func (IdentifyMsg) FromJSON

func (m IdentifyMsg) FromJSON(r io.Reader) (Msg, io.Reader, error)

func (IdentifyMsg) JSON

func (h IdentifyMsg) JSON(w io.Writer) error

type Limit

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

func Limiter

func Limiter(n int64) Limit

func (Limit) LimitReader

func (l Limit) LimitReader() int64

type Msg

type Msg interface {
	Binary(BinaryWriter) error
	JSON(io.Writer) error
	Equal(Msg) bool

	FromBinary(BinaryReader) (Msg, error)
	FromJSON(io.Reader) (Msg, io.Reader, error)

	Close() error
}

type NameOnlyClient

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

func NewBot

func NewBot(name string) *NameOnlyClient

func NewClient

func NewClient(name string, bot bool) *NameOnlyClient

func NewUser

func NewUser(name string) *NameOnlyClient

func (*NameOnlyClient) Bot

func (n *NameOnlyClient) Bot() bool

func (*NameOnlyClient) Name

func (n *NameOnlyClient) Name() string

type NeverEqual

type NeverEqual struct{}

func (NeverEqual) Equal

func (n NeverEqual) Equal(Msg) bool

type NilMsg

type NilMsg struct {
	NeverEqual
	NoClose
}

func BinaryNilMessage

func BinaryNilMessage(r BinaryReader) (m NilMsg, err error)

func JSONNilMessage

func JSONNilMessage(r io.Reader) (NilMsg, io.Reader, error)

func (NilMsg) Binary

func (m NilMsg) Binary(w BinaryWriter) error

func (NilMsg) FromBinary

func (m NilMsg) FromBinary(r BinaryReader) (Msg, error)

func (NilMsg) FromJSON

func (m NilMsg) FromJSON(r io.Reader) (Msg, io.Reader, error)

func (NilMsg) JSON

func (m NilMsg) JSON(w io.Writer) error

type NoClose

type NoClose struct{}

func (NoClose) Close

func (n NoClose) Close() error

type NoRun

type NoRun struct{}

func (NoRun) Run

func (n NoRun) Run() error

type NoRunClose

type NoRunClose struct {
	NoRun
	NoClose
}

type NoSave

type NoSave struct{}

func (NoSave) Load

func (ns NoSave) Load(file string) error

func (NoSave) NeedsSave

func (ns NoSave) NeedsSave() bool

func (NoSave) Save

func (ns NoSave) Save(file string) error

type PassthroughWriteFlusher

type PassthroughWriteFlusher struct {
	io.Writer
}

func (*PassthroughWriteFlusher) Flush

func (w *PassthroughWriteFlusher) Flush() error

type Proto

type Proto byte
const (
	ProtoNone Proto = iota
	ProtoJSON
	ProtoBinary
)

func ReadProto

func ReadProto(r io.Reader) Proto

func (Proto) Write

func (p Proto) Write(w io.Writer) error

type PubKeyMessage

type PubKeyMessage struct {
	NeverEqual
	NoClose
	// contains filtered or unexported fields
}

func BinaryPubKeyMessage

func BinaryPubKeyMessage(r BinaryReader) (p PubKeyMessage, err error)

func JSONPubKeyMessage

func JSONPubKeyMessage(r io.Reader) (PubKeyMessage, io.Reader, error)

func NewPubKeyMessage

func NewPubKeyMessage(key *crypto.Key, m PubKeyServerMessage) (PubKeyMessage, error)

func (PubKeyMessage) Binary

func (m PubKeyMessage) Binary(w BinaryWriter) error

func (PubKeyMessage) Fingerprint

func (m PubKeyMessage) Fingerprint() string

func (PubKeyMessage) FromBinary

func (m PubKeyMessage) FromBinary(r BinaryReader) (Msg, error)

func (PubKeyMessage) FromJSON

func (m PubKeyMessage) FromJSON(r io.Reader) (Msg, io.Reader, error)

func (PubKeyMessage) JSON

func (m PubKeyMessage) JSON(w io.Writer) error

type PubKeyServerMessage

type PubKeyServerMessage struct {
	NeverEqual
	NoClose
	// contains filtered or unexported fields
}

func BinaryPubKeyServerMessage

func BinaryPubKeyServerMessage(r BinaryReader) (p PubKeyServerMessage, err error)

func JSONPubKeyServerMessage

func JSONPubKeyServerMessage(r io.Reader) (PubKeyServerMessage, io.Reader, error)

func NewPubKeyServerMessage

func NewPubKeyServerMessage(key *crypto.Key) (PubKeyServerMessage, error)

func (PubKeyServerMessage) Binary

func (PubKeyServerMessage) Fingerprint

func (m PubKeyServerMessage) Fingerprint() string

func (PubKeyServerMessage) FromBinary

func (m PubKeyServerMessage) FromBinary(r BinaryReader) (Msg, error)

func (PubKeyServerMessage) FromJSON

func (m PubKeyServerMessage) FromJSON(r io.Reader) (Msg, io.Reader, error)

func (PubKeyServerMessage) JSON

func (m PubKeyServerMessage) JSON(w io.Writer) error

func (PubKeyServerMessage) PubKey added in v0.3.11

func (m PubKeyServerMessage) PubKey() *crypto.PubKey

type RWFactory

type RWFactory interface {
	Reader(io.Reader) io.Reader
	Writer(io.Writer) io.Writer

	BinaryReader(io.Reader) BinaryReader
	BinaryWriter(io.Writer) BinaryWriter
}

func NewRWFactory

func NewRWFactory(debug io.Writer) RWFactory

type Saver

type Saver interface {
	Add(d Msg)
	Each(func(Msg) bool)
	Last(int, func(Msg) bool)
}

type SendOnly

type SendOnly struct{}

func (SendOnly) HandleBIN

func (s SendOnly) HandleBIN(cl Client, r BinaryReader) error

func (SendOnly) HandleJSON

func (s SendOnly) HandleJSON(cl Client, r io.Reader) (io.Reader, error)

func (SendOnly) LimitReader

func (s SendOnly) LimitReader() int64

type Sender

type Sender interface {
	Broadcast(ClientFilter, Msg) error
	// BroadcastError(ClientFilter, error) error
	BroadcastBatch([]Batch) error
}

type StatusCode

type StatusCode byte
const (
	StatusOK StatusCode = iota
	StatusNOK
	StatusUpdateClient
	StatusNotAllowed
)

type StatusMsg

type StatusMsg struct {
	Code StatusCode `json:"code"`
	Err  string     `json:"err"`

	NeverEqual
	NoClose
}

func BinaryStatusMsg

func BinaryStatusMsg(r BinaryReader) (StatusMsg, error)

func JSONStatusMsg

func JSONStatusMsg(r io.Reader) (StatusMsg, io.Reader, error)

func (StatusMsg) Binary

func (m StatusMsg) Binary(w BinaryWriter) error

func (StatusMsg) FromBinary

func (m StatusMsg) FromBinary(r BinaryReader) (Msg, error)

func (StatusMsg) FromJSON

func (m StatusMsg) FromJSON(r io.Reader) (Msg, io.Reader, error)

func (StatusMsg) Is

func (m StatusMsg) Is(s StatusCode) bool

func (StatusMsg) JSON

func (m StatusMsg) JSON(w io.Writer) error

func (StatusMsg) OK

func (m StatusMsg) OK() bool

type StringDecoder

type StringDecoder interface{ DecodeString(string) ([]byte, error) }

type StringEncoder

type StringEncoder interface{ EncodeToString([]byte) string }

type SymmetricTestMessage

type SymmetricTestMessage struct {
	NoClose
	// contains filtered or unexported fields
}

func BinarySymmetricTestMessage

func BinarySymmetricTestMessage(r BinaryReader) (p SymmetricTestMessage, err error)

func JSONSymmetricTestMessage

func JSONSymmetricTestMessage(r io.Reader) (SymmetricTestMessage, io.Reader, error)

func NewSymmetricTestMessage

func NewSymmetricTestMessage() (SymmetricTestMessage, error)

func (SymmetricTestMessage) Binary

func (SymmetricTestMessage) Equal

func (s SymmetricTestMessage) Equal(m Msg) bool

func (SymmetricTestMessage) FromBinary

func (s SymmetricTestMessage) FromBinary(r BinaryReader) (Msg, error)

func (SymmetricTestMessage) FromJSON

func (s SymmetricTestMessage) FromJSON(r io.Reader) (Msg, io.Reader, error)

func (SymmetricTestMessage) JSON

func (s SymmetricTestMessage) JSON(w io.Writer) error

type Uploader

type Uploader interface {
	Upload(string, io.Reader) (*url.URL, error)
}

type User

type User struct {
	Name    string
	Clients int
}

type UserCollection

type UserCollection interface {
	GetUsers(ch string) []User
}

type UserUpdateHandler

type UserUpdateHandler interface {
	UserUpdate(Client, ConnectionReason) error
}

func MultiUserUpdateHandler

func MultiUserUpdateHandler(handlers ...UserUpdateHandler) UserUpdateHandler

type WriteFlusher

type WriteFlusher interface {
	io.Writer
	Flusher
}

func NewBuffered

func NewBuffered(w io.Writer) WriteFlusher

func NewPassthrough

func NewPassthrough(w io.Writer) WriteFlusher

type WriterFlusher

type WriterFlusher struct {
	io.Writer
	Flusher
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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