ircbnc

package
v0.0.0-...-3d3f267 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package ircbnc provides the backend for the GoshuBNC IRC bouncer.

Index

Constants

View Source
const (
	// SemVer is the semantic version of GoshuBNC.
	SemVer = "0.1.0-unreleased"
)

Variables

View Source
var ClientCommands map[string]ClientCommand

ClientCommands holds all commands executable by a client connected to a listener.

View Source
var HookIrcRawName = "irc.raw"
View Source
var HookListenerCloseName = "listener.close"
View Source
var HookNewListenerName = "listener.new"
View Source
var HookStateSentName = "listener.statesent"
View Source
var (
	// Ver is the full version of GoshuBNC, used in responses to clients.
	Ver = fmt.Sprintf("goshubnc-%s", SemVer)
)

Functions

func BncName

func BncName(name string) (string, error)

BncName takes the given name and returns a casefolded name appropriate for use with ircbnc. This includes usernames, network names, etc.

func CapAccountNotify

func CapAccountNotify(caps *CapManager)

*

  • CAP: account-notify

func CapAccountTag

func CapAccountTag(caps *CapManager)

*

  • CAP: account-tag

func CapAwayNotify

func CapAwayNotify(caps *CapManager)

*

  • CAP: away-notify

func CapBatch

func CapBatch(caps *CapManager)

*

  • CAP: batch
  • Not used on it's own, but other commands such as CHATHISTORY make use of it

func CapExtendedJoin

func CapExtendedJoin(caps *CapManager)

*

  • CAP: extended-join

func CapInviteNotify

func CapInviteNotify(caps *CapManager)

*

  • CAP: invite-notify

func CapServerTime

func CapServerTime(caps *CapManager)

*

  • CAP: server-time

func CapUserhostInNames

func CapUserhostInNames(caps *CapManager)

*

  • CAP: userhost-in-names

func IrcName

func IrcName(name string, isChannel bool) (string, error)

IrcName returns a name appropriate for IRC use (nick/user/channel), or an error if the name is bad.

func NewListener

func NewListener(m *Manager, conn net.Conn)

NewListener creates a new Listener.

func SplitMask

func SplitMask(mask string) (string, string, string)

Types

type CapManager

type CapManager struct {
	Supported            map[string]string
	FnsInitListener      map[string]func(*Listener)
	FnsMessageToClient   []func(*Listener, *ircmsg.IrcMessage) bool
	FnsMessageFromClient []func(*Listener, *ircmsg.IrcMessage) bool
}
var Capabilities CapManager

func (*CapManager) FilterSupported

func (caps *CapManager) FilterSupported(requested []string) map[string]string

FilterSupported filters the supported CAPs by the requested

func (*CapManager) InitCapOnListener

func (caps *CapManager) InitCapOnListener(listener *Listener, cap string)

MessageToClient runs messages through any CAPs before being sent to the client

func (*CapManager) MessageFromClient

func (caps *CapManager) MessageFromClient(listener *Listener, message *ircmsg.IrcMessage) bool

MessageFromClient runs messages received from a client through any CAPs

func (*CapManager) MessageToClient

func (caps *CapManager) MessageToClient(listener *Listener, message *ircmsg.IrcMessage) bool

MessageToClient runs messages through any CAPs before being sent to the client

func (*CapManager) SupportedString

func (caps *CapManager) SupportedString() string

SupportedString returns a list ready to send to the client of all our CAPs

type ClientCommand

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

ClientCommand represents a command accepted on a listener.

func (*ClientCommand) Run

func (cmd *ClientCommand) Run(listener *Listener, msg ircmsg.IrcMessage) bool

Run runs this command with the given listener/message.

type Config

type Config struct {
	Bouncer struct {
		Storage      map[string]string
		Listeners    []string
		TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
		Logging      map[string]string
	}
}

Config defines a configuration file for GoshuBNC

func LoadConfig

func LoadConfig(filename string) (config *Config, err error)

LoadConfig returns a Config instance

func (*Config) TLSListeners

func (conf *Config) TLSListeners() map[string]*tls.Config

TLSListeners returns a map of tls.Config objects from our config

type DataStoreInterface

type DataStoreInterface interface {
	Init(manager *Manager) error
	Setup() error
	GetAllUsers() []*User
	GetUserById(id string) *User
	GetUserByUsername(username string) *User
	SaveUser(*User) error
	SetUserPassword(user *User, newPassword string)
	AuthUser(username string, password string) (authedUserId string, authSuccess bool)
	GetUserNetworks(userId string)
	SaveConnection(connection *ServerConnection) error
	DelConnection(connection *ServerConnection) error
}

type HookEmitter

type HookEmitter struct {
	Registered map[string][]func(interface{})
}

func MakeHookEmitter

func MakeHookEmitter() HookEmitter

func (*HookEmitter) Dispatch

func (hooks *HookEmitter) Dispatch(hookName string, data interface{})

func (*HookEmitter) Register

func (hooks *HookEmitter) Register(hookName string, p func(interface{}))

type HookIrcRaw

type HookIrcRaw struct {
	Listener   *Listener
	FromServer bool
	FromClient bool
	User       *User
	Server     *ServerConnection
	Raw        string
	Message    ircmsg.IrcMessage
	Halt       bool
}

type HookListenerClose

type HookListenerClose struct {
	Listener *Listener
}

type HookNewListener

type HookNewListener struct {
	Listener *Listener
	Halt     bool
}

type HookStateSent

type HookStateSent struct {
	Listener *Listener
	Server   *ServerConnection
}

type Listener

type Listener struct {
	Socket Socket

	Manager        *Manager
	ConnectTime    time.Time
	Caps           map[string]string
	ExtraISupports map[string]string
	TagsEnabled    bool
	ClientNick     string
	Source         string
	Registered     bool

	User             *User
	ServerConnection *ServerConnection
	// contains filtered or unexported fields
}

Listener is a listener for a client connected directly to us.

func (*Listener) DumpChannels

func (listener *Listener) DumpChannels()

DumpChannels dumps the active channels to the listener.

func (*Listener) DumpRegistration

func (listener *Listener) DumpRegistration()

DumpRegistration dumps the registration numerics/replies to the listener.

func (*Listener) IsCapEnabled

func (listener *Listener) IsCapEnabled(cap string) bool

func (*Listener) RunSocketReader

func (listener *Listener) RunSocketReader()

RunSocketReader reads lines from the listener socket and dispatches them as appropriate.

func (*Listener) Send

func (listener *Listener) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error

Send sends an IRC line to the user.

func (*Listener) SendExtraISupports

func (listener *Listener) SendExtraISupports()

func (*Listener) SendLine

func (listener *Listener) SendLine(line string)

SendLine sends a raw string line to the user.

func (*Listener) SendMessage

func (listener *Listener) SendMessage(msg *ircmsg.IrcMessage) error

SendMessage sends an IrcMessage to the user

func (*Listener) SendNilConnect

func (listener *Listener) SendNilConnect()

SendNilConnect sends a connection init (001+ERR_NOMOTD) to the listener when they are not connected to a server.

func (*Listener) SendStatus

func (listener *Listener) SendStatus(line string)

SendStatus sends a status PRIVMSG to the user.

type Manager

type Manager struct {
	Config   *Config
	Ds       DataStoreInterface
	Messages MessageDatastore

	Users     map[string]*User
	Listeners []net.Listener

	Source       string
	StatusNick   string
	StatusSource string

	Bus HookEmitter

	Salt []byte
	// contains filtered or unexported fields
}

Manager handles the different components that keep GoshuBNC spinning.

var (
	// QuitSignals is the list of signals we quit on
	//TODO(dan): Rehash on one of these signals instead, same as Oragono.
	QuitSignals = []os.Signal{syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGQUIT}
	// BNC: The global instance of Manager.
	// TODO: NewManager() sets this each time it's run. It's only run once so no issue.. but it's not tidy
	BNC *Manager
)

func NewManager

func NewManager(config *Config, ds DataStoreInterface) *Manager

NewManager create a new IRC bouncer from the given config and database.

func (*Manager) Run

func (m *Manager) Run() error

Run starts the bouncer, creating the listeners and server connections.

type MessageDatastore

type MessageDatastore interface {
	Store(hookEvent *HookIrcRaw)
	GetFromTime(userID string, networkID string, bufferName string, timeFrom time.Time, num int) []*ircmsg.IrcMessage
	GetBeforeTime(userID string, networkID string, bufferName string, timeFrom time.Time, num int) []*ircmsg.IrcMessage
	Search(userID string, networkID string, bufferName string, timeFrom time.Time, timeTo time.Time, num int) []*ircmsg.IrcMessage

	SupportsStore() bool
	SupportsRetrieve() bool
	SupportsSearch() bool
}

type RegistrationLocks

type RegistrationLocks struct {
	sync.Mutex
	Cap  bool
	Nick bool
	User bool
	Pass bool
}

RegistrationLocks ensure the user can't complete registration until they've finished the reg process.

func (*RegistrationLocks) Completed

func (rl *RegistrationLocks) Completed() bool

Completed returns true if all of our registration locks have been completed.

func (*RegistrationLocks) Set

func (rl *RegistrationLocks) Set(lockName string, val bool)

Set sets the given registration lock.

type ServerConnection

type ServerConnection struct {
	Name    string
	User    *User
	Enabled bool

	Nickname    string
	FbNickname  string
	Username    string
	Realname    string
	CurrentMask string
	Buffers     ServerConnectionBuffers

	ListenersLock sync.Mutex
	Listeners     []*Listener

	Password  string
	Addresses []ServerConnectionAddress
	Foo       *ircclient.Client
	// contains filtered or unexported fields
}

ServerConnection represents a connection to an IRC server.

func NewServerConnection

func NewServerConnection() *ServerConnection

func (*ServerConnection) AddListener

func (sc *ServerConnection) AddListener(listener *Listener)

AddListener adds the given listener to this ServerConnection.

func (*ServerConnection) Connect

func (sc *ServerConnection) Connect()

func (*ServerConnection) Disconnect

func (sc *ServerConnection) Disconnect()

func (*ServerConnection) DumpChannels

func (sc *ServerConnection) DumpChannels(listener *Listener)

func (*ServerConnection) DumpRegistration

func (sc *ServerConnection) DumpRegistration(listener *Listener)

DumpRegistration dumps the registration messages of this server to the given Listener.

func (*ServerConnection) ReadyToConnect

func (sc *ServerConnection) ReadyToConnect() bool

func (*ServerConnection) RemoveListener

func (sc *ServerConnection) RemoveListener(listener *Listener)

func (*ServerConnection) Save

func (sc *ServerConnection) Save() error

type ServerConnectionAddress

type ServerConnectionAddress struct {
	Host      string
	Port      int
	UseTLS    bool
	VerifyTLS bool
}

type ServerConnectionAddresses

type ServerConnectionAddresses []ServerConnectionAddress

type ServerConnectionBuffer

type ServerConnectionBuffer struct {
	Channel  bool
	Name     string
	Key      string
	UseKey   bool
	LastSeen time.Time
}

type ServerConnectionBuffers

type ServerConnectionBuffers map[string]*ServerConnectionBuffer

func (*ServerConnectionBuffers) Add

func (buffers *ServerConnectionBuffers) Add(buffer *ServerConnectionBuffer)

func (*ServerConnectionBuffers) Get

func (buffers *ServerConnectionBuffers) Get(findName string) *ServerConnectionBuffer

func (*ServerConnectionBuffers) Map

TODO(dan): Why do we use this function instead of just having ServerConnectionBuffers be a struct with a hidden map?

func (*ServerConnectionBuffers) Remove

func (buffers *ServerConnectionBuffers) Remove(name string)

type Socket

type Socket struct {
	MaxSendQBytes uint64
	// contains filtered or unexported fields
}

Socket represents an IRC socket.

func NewSocket

func NewSocket(conn net.Conn, maxSendQBytes uint64) Socket

NewSocket returns a new Socket.

func (*Socket) CertFP

func (socket *Socket) CertFP() (string, error)

CertFP returns the fingerprint of the certificate provided by our peer.

func (*Socket) Close

func (socket *Socket) Close()

Close stops a Socket from being able to send/receive any more data.

func (*Socket) IsClosed

func (socket *Socket) IsClosed() bool

IsClosed returns whether the socket is closed.

func (*Socket) Read

func (socket *Socket) Read() (string, error)

Read returns a single IRC line from a Socket.

func (*Socket) RunSocketWriter

func (socket *Socket) RunSocketWriter()

RunSocketWriter starts writing messages to the outgoing socket.

func (*Socket) SetFinalData

func (socket *Socket) SetFinalData(data string)

SetFinalData sets the final data to send when the SocketWriter closes.

func (*Socket) Write

func (socket *Socket) Write(data string) error

Write sends the given string out of Socket.

func (*Socket) WriteLine

func (socket *Socket) WriteLine(line string) error

WriteLine writes the given line out of Socket.

type TLSListenConfig

type TLSListenConfig struct {
	Cert string
	Key  string
}

TLSListenConfig defines configuration options for listening on TLS

func (*TLSListenConfig) Config

func (conf *TLSListenConfig) Config() (*tls.Config, error)

Config returns the TLS certificate assicated with this TLSListenConfig

type User

type User struct {
	Manager *Manager
	Config  *Config

	ID   string
	Name string
	Role string

	HashedPassword []byte
	Salt           []byte
	Permissions    []string

	DefaultNick   string
	DefaultFbNick string
	DefaultUser   string
	DefaultReal   string

	Networks map[string]*ServerConnection
}

User represents an ircbnc user.

func NewUser

func NewUser(manager *Manager) *User

func (*User) StartServerConnections

func (user *User) StartServerConnections()

StartServerConnections starts running the server connections of this user.

Directories

Path Synopsis
components
datastores

Jump to

Keyboard shortcuts

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