Documentation ¶
Index ¶
- Variables
- type Channel
- type Client
- func (c *Client) BatchSend(messages []*irc.Message) error
- func (c *Client) Disconnect()
- func (c *Client) Heartbeat(ctx context.Context) error
- func (c *Client) Listen(ctx context.Context) error
- func (c *Client) LogEntry() *log.Entry
- func (c *Client) LogFields() log.Fields
- func (c *Client) MaybeRun(msg *irc.Message) (bool, error)
- func (c *Client) Ping(nickname string)
- func (c *Client) Receive() (*irc.Message, error)
- func (c *Client) Send(msg *irc.Message) error
- type ClientCommandHook
- type ClientConfig
- type Connection
- type HTTPConfig
- type HTTPHandler
- type HTTPServer
- type HTTPWrapper
- type Identity
- type Network
- type NetworkCommandHook
- type NetworkConfig
- type NetworkUpdateRequest
- type NetworkUpdateResponse
- type Router
- type Server
- type ServerConfig
- type User
- type UserConfig
- type UserUpdateRequest
- type UserUpdateResponse
Constants ¶
This section is empty.
Variables ¶
var ( ErrDisconnected = errors.New("Client disconnected.") ClientCommandTable = map[string]ClientCommandHook{ irc.USER: (*Client).user, irc.NICK: (*Client).nick, irc.PASS: (*Client).pass, irc.QUIT: (*Client).quit, irc.CAP: (*Client).cap, } )
var NetworkCommandTable = map[string]NetworkCommandHook{ irc.PING: (*Network).ping, irc.JOIN: (*Network).join, irc.RPL_WELCOME: (*Network).rpl_welcome, irc.RPL_YOURHOST: (*Network).rpl_welcome, irc.RPL_CREATED: (*Network).rpl_welcome, irc.RPL_MYINFO: (*Network).rpl_welcome, irc.RPL_BOUNCE: (*Network).rpl_welcome, irc.RPL_NAMREPLY: (*Network).rpl_namreply, }
NetworkCommandTable maps IRC to commands to hooks. Whenever the client receives a message, it looks up the command in the CommandTable and runs the corresponding function.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
func NewChannel ¶
func (*Channel) RemoveNick ¶
RemoveNick removes a given nick form the channel.
type Client ¶
type Client struct { Connection net.Conn `json:",omitempty"` Buffer chan *irc.Message `json:",omitempty"` Ident *Identity `json:",omitempty"` Encoder *irc.Encoder `json:",omitempty"` Decoder *irc.Decoder `json:",omitempty"` Reader *bufio.Reader `json:",omitempty"` }
Client represents the actual Connection between the User and the Server. Unlike Network which represents both the Connection and metadata, Client is seperate from User so it can run independetly before identifying itself.
func NewClient ¶
func NewClient(config ClientConfig) (*Client, error)
New takes in a ClientConfig and returns a new Client object.
func (*Client) Heartbeat ¶
heartbeat sends a ping message every 30 seonds to the client. It takes a done channel as a replacement to context. TODO: Close the `done` channel if the client doesn't reply with a PONG.
func (*Client) Listen ¶
Listen reads, sanitizes, and forwards all messages sent from the Client directed towards the Network. In its current state, this blocking process should only exit if...
- the reader throws an error
- the Client disconnects
type ClientCommandHook ¶
type ClientConfig ¶
type Connection ¶
type HTTPConfig ¶
type HTTPConfig struct {
Advertise string
}
type HTTPHandler ¶
type HTTPHandler func(resp http.ResponseWriter, req *http.Request)
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
func NewHTTPServer ¶
func NewHTTPServer(s *Server, c *HTTPConfig) (*HTTPServer, error)
NewHTTPServer configures a new multiplexer and listener and returns the running HTTPServer.
type HTTPWrapper ¶
type HTTPWrapper func(resp http.ResponseWriter, req *http.Request) (interface{}, error)
type Identity ¶
type Identity struct { Username string `json:"username"` Nickname string `json:"nickname"` Realname string `json:"realname"` Password string `json:"password"` }
Identity represnts the necessary information to authenticate with a Network. See RFC 2812 § 3.1
func (*Identity) CanAuthenticate ¶
func (*Identity) HasNetwork ¶
HasNetwork returns true if the username is username/network pair.
func (*Identity) ParsedNetwork ¶
ParsedNetwork returns the string following a '/' in the username. This method is naive and assumes that a username will only contain a single slash, and the substring following the delimeter is the desired network.
func (*Identity) ParsedUsername ¶
ParsedUsername returns the string preceding a '/' in the username. This method is naive and assumes the desired username is the first substring after splitting by a forward slash delimeter. This method should be used instead of accessing the field directly.
type Network ¶
type Network struct { Config *NetworkConfig Name string `json:"name"` URI string `json:"uri"` Ident *Identity `json:"ident,omitempty"` Channels []*Channel `json:",omitempty"` Buffer chan *irc.Message `json:"-,omitempty"` Connection *irc.Conn `json:"-,omitempty"` ClientReplies []*irc.Message `json:"-,omitempty"` }
Network represents an IRC network. Each network has a URI, and, because Users own the Network object, each Network stores the User's Identity as well.
func NewNetwork ¶
func NewNetwork(config *NetworkConfig) (*Network, error)
New takes in a Network Config and returns a new Network object. In this case, all configs are manadatory, but, in its current state, New doesn't throw any errors.
func (*Network) Listen ¶
Listen attempts to connect and listen if the Network isn't already connected. If the Network's Connection is nil, Listen reads parses, and forwards all messages from the Network to the Client. In it's current state, this blocking function should exit if the Network encounters an error when receiving messages.
type NetworkCommandHook ¶
type NetworkConfig ¶
type NetworkUpdateRequest ¶
type NetworkUpdateResponse ¶
type NetworkUpdateResponse struct {
Name string
}
type Router ¶
func (*Router) Route ¶
Route passes messages from the given Network buffer to the Client buffer, and visa versa. Route also calls heartbeat to periodically ping the Client's Connection. If the Client doesn' respond to the Ping or encounters an error when sending to either the Client or Network, Route returns.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the configuration for all of Carousel. It maintains a list of all Users, as well general server information (ie. URI).
func NewServer ¶
func NewServer(config *ServerConfig) (*Server, error)
type ServerConfig ¶
type User ¶
type User struct { Config *UserConfig Username string `json:"username"` Password string `json:"password"` Networks []*Network `json:"network,omitempty"` Client *Client `json:",omitempty"` }
User represents the individual Users's account and network config. Currently, a user can only connect to a single network, and each user owns their own router to pass messages.
func NewUser ¶
func NewUser(config *UserConfig) (*User, error)
func (*User) Authorize ¶
Authorized compares the given password with the password hash stored in the config. The user's password isn't stored in plaintext (for very obvious reasons, so we have to hash and salt the supplied password before comparing)
func (*User) Network ¶
Network returns the network object with matching name, and returns nil if no match is found.
func (*User) NetworkOrDefault ¶
NetworkOrDefault, like Network, returns the network with matching name or returns nil if no match if found. If the given string is empty, however, it returns the default network (for now, the default is the first in a non-empty network list.
type UserConfig ¶
type UserUpdateRequest ¶
type UserUpdateResponse ¶
type UserUpdateResponse struct {
Username string
}