core

package
v0.0.0-...-e643345 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2017 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ClientSuicide    = errors.New("client doesn't want to live anymore")
	ErrWrongPassword = errors.New("wrong password")
	ErrChannel       = errors.New("channel error")
	ErrUnknown       = errors.New("unknown error")
)
View Source
var ErrPipeClosed error = errors.New("pipe is closed")

Functions

This section is empty.

Types

type Channel

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

func NewChannel

func NewChannel(address string, port int, password string, timeout int) *Channel

func (*Channel) Addr

func (c *Channel) Addr() net.Addr

Addr return the ip address of the channel

func (*Channel) Close

func (c *Channel) Close() (err error)

func (*Channel) Join

func (c *Channel) Join(conn net.Conn)

Join create a pipe between the channel and the given connection and start listening for client message, after executing the authentication procedure (the client must know the protocol)

func (*Channel) Open

func (c *Channel) Open() error

Open make the channel listen for connection and handling received message

func (*Channel) String

func (c *Channel) String() string

type Client

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

func NewClient

func NewClient(name string) *Client

func (*Client) AddListener

func (c *Client) AddListener(listener MsgListener)

func (*Client) Bye

func (c *Client) Bye() error

func (*Client) CloseChan

func (c *Client) CloseChan(name string) error

func (*Client) Connect

func (c *Client) Connect(name, address string, port int, password string) error

func (*Client) ConnectKnown

func (c *Client) ConnectKnown(name string) error

func (*Client) CreateChan

func (c *Client) CreateChan(name, address string, port int, password string, timeout int) error

func (*Client) CreateConnectChan

func (c *Client) CreateConnectChan(name, address string, port int, password string, timeout int) error

func (*Client) Die

func (c *Client) Die() error

func (*Client) Forget

func (c *Client) Forget(name string) error

func (*Client) Identity

func (c *Client) Identity() Identity

func (*Client) List

func (c *Client) List() error

func (*Client) ListKnownChan

func (c *Client) ListKnownChan() func(string) []string

func (*Client) ListOwnChan

func (c *Client) ListOwnChan() func(string) []string

func (*Client) Me

func (c *Client) Me() error

func (*Client) SendMessage

func (c *Client) SendMessage(text string) error

func (*Client) String

func (c *Client) String() string

type IChannel

type IChannel interface {
	Open() error
	Close() error
	Addr() net.Addr
}

type IClient

type IClient interface {
	Identity() Identity
	AddListener(listener MsgListener)
	CreateConnectChan(name, address string, port int, password string, timeout int) error
	CreateChan(name, address string, port int, password string, timeout int) error
	Connect(name, address string, port int, password string) error
	ConnectKnown(name string) error
	ListKnownChan() func(string) []string
	ListOwnChan() func(string) []string
	CloseChan(name string) error
	Bye() error
	Die() error
	Forget(name string) error
	Me() error
	List() error
	SendMessage(text string) error
}

type IPipe

type IPipe interface {
	Read() (Message, error)
	Write(Message) error
	Close() error
}

type IRegistry

type IRegistry interface {
	Push(Identity, *Pipe)
	Get(Identity) (*Pipe, error)
	Pop(Identity) (*Pipe, error)
	Exists(Identity) bool
	Foreach(callback func(Identity, *Pipe))
}

type Identity

type Identity struct {
	// Must be public for marshalling
	Name string
	Hash string
}

func NewIdentity

func NewIdentity(name string) *Identity

func NewIdentityFromConn

func NewIdentityFromConn(name string, conn net.Conn) *Identity

func (*Identity) String

func (id *Identity) String() string

type Interceptor

type Interceptor func(p *Pipe, msg *Message)

type KnownChan

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

func (*KnownChan) String

func (k *KnownChan) String() string

type Message

type Message struct {
	// Must be public for marshalling
	Text      string
	Type      TMsg
	Sender    Identity
	Timestamp time.Time
}

func NewMsg

func NewMsg(sender Identity, t TMsg) *Message

func NewMsgPassword

func NewMsgPassword(sender Identity, password string) *Message

func NewMsgSysChannel

func NewMsgSysChannel(sender Identity, text string) *Message

func NewMsgSysClient

func NewMsgSysClient(sender Identity, text string) *Message

func NewMsgText

func NewMsgText(sender Identity, text string) *Message

type MsgListener

type MsgListener func(*Message)

type Pipe

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

func NewPipe

func NewPipe(conn net.Conn) *Pipe

func (*Pipe) Close

func (p *Pipe) Close() error

func (*Pipe) IsOpen

func (p *Pipe) IsOpen() bool

func (*Pipe) Read

func (p *Pipe) Read() (msg Message, err error)

func (*Pipe) Write

func (p *Pipe) Write(msg Message) (err error)

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Exists

func (r *Registry) Exists(id Identity) bool

func (*Registry) Foreach

func (r *Registry) Foreach(callback func(Identity, *Pipe))

func (*Registry) Get

func (r *Registry) Get(id Identity) (*Pipe, error)

func (*Registry) Pop

func (r *Registry) Pop(id Identity) (*Pipe, error)

func (*Registry) Push

func (r *Registry) Push(id Identity, pipe *Pipe)

type TMsg

type TMsg int
const (
	HELLO           TMsg = 0
	TEXT            TMsg = 1
	WELCOME         TMsg = 2
	WELCOME_BACK    TMsg = 3
	PASSWORD_PLEASE TMsg = 4
	PASSWORD        TMsg = 5
	WRONG_PASSWORD  TMsg = 6
	ERROR           TMsg = 7
	SYS_CLIENT      TMsg = 8
	SYS_CHANNEL     TMsg = 9
)

Jump to

Keyboard shortcuts

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