ircserver

package
v0.0.0-...-e7dcbf3 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package ircserver implements an IRC server which strictly adheres to a processing model where output is only ever generated in response to input, and only depends on state that is local to the IRC server.

That means the output of two IRC server instances will be byte-for-byte identical if you feed them exactly the same input (in the same order), which is what RobustIRC does when recovering from a raft snapshot.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrSessionNotYetSeen is returned when the session was not (yet?) seen on
	// this follower. We cannot say with confidence that it does not exist.
	ErrSessionNotYetSeen = errors.New("Session not yet seen")

	// ErrNoSuchSession is returned when the session definitely does not exist.
	ErrNoSuchSession = errors.New("No such session")

	// ErrSessionLimitReached is returned when the number of sessions exceeds the configured limit.
	ErrSessionLimitReached = errors.New("MaxSessions limit reached")

	// CursorEOF is returned by a logCursor when there are no more messages.
	CursorEOF = errors.New("No more messages")
)
View Source
var (
	Commands = make(map[string]*ircCommand)
)

Functions

func ChanToLower

func ChanToLower(channelname string) lcChan

ChanToLower converts a channel to lower case.

func IsServicesNickname

func IsServicesNickname(nick string) bool

func IsValidChannel

func IsValidChannel(channel string) bool

func IsValidNickname

func IsValidNickname(nick string) bool

IsValidNickname returns true if the provided nickname is valid according to RFC2812 (see https://tools.ietf.org/html/rfc2812#section-2.3.1), otherwise false.

func NickToLower

func NickToLower(nick string) lcNick

NickToLower converts a nickname to lower case, following RFC2812:

Because of IRC's scandanavian origin, the characters {}| are considered to be the lower case equivalents of the characters []\, respectively. This is a critical issue when determining the equivalence of two nicknames.

Types

type IRCServer

type IRCServer struct {

	// ServerPrefix is the prefix for output messages that come from the
	// server, as opposed to from a client.
	ServerPrefix *irc.Prefix

	// serverCreation is the time at which the IRCServer object was created.
	// Used for the RPL_CREATED message.
	ServerCreation time.Time

	// Config contains the network configuration.
	Config   config.Network
	ConfigMu *sync.RWMutex
	// contains filtered or unexported fields
}

func NewIRCServer

func NewIRCServer(networkname string, serverCreation time.Time) *IRCServer

NewIRCServer returns a new IRC server.

func (*IRCServer) Banned

func (i *IRCServer) Banned(remoteAddr string) string

func (*IRCServer) ChannelLimit

func (i *IRCServer) ChannelLimit() uint64

func (*IRCServer) CreateSession

func (i *IRCServer) CreateSession(id robust.Id, auth string, timestamp time.Time) error

CreateSession creates a new session (equivalent to an IRC connection).

func (*IRCServer) ExpireSessions

func (i *IRCServer) ExpireSessions() []*robust.Message

ExpireSessions returns DeleteSession robust.Messages for all sessions that are older than timeout. These messages are then applied to raft.

func (*IRCServer) GetAuth

func (i *IRCServer) GetAuth(sessionid robust.Id) (string, error)

GetAuth returns the authentication string of |sessionid|, a random shared secret between the RobustIRC network and the client to prevent session hijacking.

func (*IRCServer) GetNick

func (i *IRCServer) GetNick(sessionid robust.Id) string

GetNick returns the nickname of |sessionid|, or the empty string if that session does not exist.

func (*IRCServer) GetSession

func (i *IRCServer) GetSession(id robust.Id) (*Session, error)

GetSession returns a pointer to the session specified by 'id'.

It returns ErrNoSuchSession when the session definitely does not exist (based on the timestamp), but ErrSessionNotYetSeen when the session might exist in the future, but was not yet seen on this IRC instance server (perhaps due to raft delay).

func (*IRCServer) GetSessions

func (i *IRCServer) GetSessions() map[robust.Id]Session

GetSessions returns a copy of sessions that can be used in the status handler (i.e. it goes stale, but doesn’t block other operations).

func (*IRCServer) LastPostMessage

func (i *IRCServer) LastPostMessage(sessionid robust.Id) uint64

LastPostMessage returns |sessionid|’s last processed client message id and the corresponding reply (for duplicate detection).

func (*IRCServer) Marshal

func (i *IRCServer) Marshal(lastIncludedIndex uint64) ([]byte, error)

func (*IRCServer) MaybeDeleteSession

func (i *IRCServer) MaybeDeleteSession(session robust.Id)

func (*IRCServer) NumChannels

func (i *IRCServer) NumChannels() int

NumSessions returns the current number of channels.

func (*IRCServer) NumSessions

func (i *IRCServer) NumSessions() int

NumSessions returns the current number of sessions.

func (*IRCServer) OriginWhitelisted

func (i *IRCServer) OriginWhitelisted(origin string) bool

func (*IRCServer) ProcessMessage

func (i *IRCServer) ProcessMessage(msg *robust.Message, ircmsg *irc.Message) *Replyctx

ProcessMessage modifies state in response to 'message' and returns zero or more IRC messages in response to 'message'. These messages can then be stored for eventual retrieval by the clients by calling SendMessages.

func (*IRCServer) SessionLimit

func (i *IRCServer) SessionLimit() uint64

func (*IRCServer) SetLastProcessed

func (i *IRCServer) SetLastProcessed(id robust.Id)

func (*IRCServer) ThrottleUntil

func (i *IRCServer) ThrottleUntil(sessionid robust.Id) time.Time

ThrottleUntil returns the last activity of |sessionid| or the zero time.

func (*IRCServer) TrustedBridge

func (i *IRCServer) TrustedBridge(authHeader string) string

func (*IRCServer) Unmarshal

func (i *IRCServer) Unmarshal(data []byte) (uint64, error)

Unmarshal treats |data| as a protobuf-encoded snapshot of IRCServer state and applies it to the IRCServer. It returns the last included ircstore index of the snapshot.

func (*IRCServer) UpdateLastClientMessageID

func (i *IRCServer) UpdateLastClientMessageID(msg *robust.Message) error

UpdateLastMessage stores the clientmessageid of the last message in the corresponding session, so that duplicate messages are not persisted twice.

type Replyctx

type Replyctx struct {
	Messages []*robust.Message
	// contains filtered or unexported fields
}

Replyctx is a reply context, i.e. information necessary when replying to an IRC message. A reply context object will be passed to all cmd* functions and the send* functions use it to keep track of the replyid for example.

type Session

type Session struct {
	Id robust.Id

	Nick              string
	Username          string
	Realname          string
	Channels          map[lcChan]bool
	LastActivity      time.Time
	LastNonPing       time.Time
	LastSolvedCaptcha time.Time
	Operator          bool
	AwayMsg           string
	Created           int64

	// The (raw) password from a PASS command.
	Pass string

	Server bool

	RemoteAddr string // network address of the most recent message
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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