Documentation ¶
Index ¶
- Variables
- type AdjListBuddyListStore
- func (store *AdjListBuddyListStore) AddBuddy(userScreenName, buddyScreenName string)
- func (store *AdjListBuddyListStore) Buddies(userScreenName string) []string
- func (store *AdjListBuddyListStore) DeleteBuddy(userScreenName, buddyScreenName string)
- func (store *AdjListBuddyListStore) DeleteUser(userScreenName string)
- func (store *AdjListBuddyListStore) WhoAddedUser(userScreenName string) []string
- type BlockedState
- type ChatRegistry
- type ChatRoom
- type InMemorySessionManager
- func (s *InMemorySessionManager) AddSession(sessID string, screenName string) *Session
- func (s *InMemorySessionManager) AllSessions() []*Session
- func (s *InMemorySessionManager) Empty() bool
- func (s *InMemorySessionManager) RelayToAll(ctx context.Context, msg wire.SNACMessage)
- func (s *InMemorySessionManager) RelayToAllExcept(ctx context.Context, except *Session, msg wire.SNACMessage)
- func (s *InMemorySessionManager) RelayToScreenName(ctx context.Context, screenName string, msg wire.SNACMessage)
- func (s *InMemorySessionManager) RelayToScreenNames(ctx context.Context, screenNames []string, msg wire.SNACMessage)
- func (s *InMemorySessionManager) RemoveSession(sess *Session)
- func (s *InMemorySessionManager) RetrieveByScreenName(screenName string) *Session
- func (s *InMemorySessionManager) RetrieveSession(sessionID string) *Session
- type SQLiteUserStore
- func (f SQLiteUserStore) AdjacentUsers(screenName string) ([]string, error)
- func (f SQLiteUserStore) AllUsers() ([]User, error)
- func (f SQLiteUserStore) BARTRetrieve(hash []byte) ([]byte, error)
- func (f SQLiteUserStore) BARTUpsert(itemHash []byte, body []byte) error
- func (f SQLiteUserStore) BlockedState(screenNameA, screenNameB string) (BlockedState, error)
- func (f SQLiteUserStore) Buddies(screenName string) ([]string, error)
- func (f SQLiteUserStore) Feedbag(screenName string) ([]wire.FeedbagItem, error)
- func (f SQLiteUserStore) FeedbagDelete(screenName string, items []wire.FeedbagItem) error
- func (f SQLiteUserStore) FeedbagLastModified(screenName string) (time.Time, error)
- func (f SQLiteUserStore) FeedbagUpsert(screenName string, items []wire.FeedbagItem) error
- func (f SQLiteUserStore) InsertUser(u User) error
- func (f SQLiteUserStore) Profile(screenName string) (string, error)
- func (f SQLiteUserStore) SetProfile(screenName string, body string) error
- func (f SQLiteUserStore) SetUserPassword(u User) error
- func (f SQLiteUserStore) User(screenName string) (*User, error)
- type SessSendStatus
- type Session
- func (s *Session) AwayMessage() string
- func (s *Session) Caps() [][16]byte
- func (s *Session) ChatRoomCookie() string
- func (s *Session) Close()
- func (s *Session) Closed() <-chan struct{}
- func (s *Session) ID() string
- func (s *Session) IncrementWarning(incr uint16)
- func (s *Session) Invisible() bool
- func (s *Session) ReceiveMessage() chan wire.SNACMessage
- func (s *Session) RelayMessage(msg wire.SNACMessage) SessSendStatus
- func (s *Session) ScreenName() string
- func (s *Session) SetAwayMessage(awayMessage string)
- func (s *Session) SetCaps(caps [][16]byte)
- func (s *Session) SetChatRoomCookie(cookie string)
- func (s *Session) SetID(ID string)
- func (s *Session) SetIdle(dur time.Duration)
- func (s *Session) SetInvisible(invisible bool)
- func (s *Session) SetScreenName(screenName string)
- func (s *Session) SetSignonComplete()
- func (s *Session) SetSignonTime(t time.Time)
- func (s *Session) SignonComplete() bool
- func (s *Session) TLVUserInfo() wire.TLVUserInfo
- func (s *Session) UnsetIdle()
- func (s *Session) Warning() uint16
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDupUser indicates that a user already exists. ErrDupUser = errors.New("user already exists") // ErrNoUser indicates that a user does not exist. ErrNoUser = errors.New("user does not exist") )
var ErrChatRoomNotFound = errors.New("chat room not found")
ErrChatRoomNotFound indicates that a chat room lookup failed.
Functions ¶
This section is empty.
Types ¶
type AdjListBuddyListStore ¶ added in v0.3.0
type AdjListBuddyListStore struct {
// contains filtered or unexported fields
}
AdjListBuddyListStore implements a buddy list using an adjacency list.
func NewAdjListBuddyListStore ¶ added in v0.3.0
func NewAdjListBuddyListStore() *AdjListBuddyListStore
NewAdjListBuddyListStore initializes a new instance of AdjListBuddyListStore.
func (*AdjListBuddyListStore) AddBuddy ¶ added in v0.3.0
func (store *AdjListBuddyListStore) AddBuddy(userScreenName, buddyScreenName string)
AddBuddy adds buddyScreenName to userScreenName's buddy list.
func (*AdjListBuddyListStore) Buddies ¶ added in v0.3.0
func (store *AdjListBuddyListStore) Buddies(userScreenName string) []string
Buddies returns a list of all buddies associated with the specified userScreenName.
func (*AdjListBuddyListStore) DeleteBuddy ¶ added in v0.3.0
func (store *AdjListBuddyListStore) DeleteBuddy(userScreenName, buddyScreenName string)
DeleteBuddy removes buddyScreenName from userScreenName's buddy list.
func (*AdjListBuddyListStore) DeleteUser ¶ added in v0.3.0
func (store *AdjListBuddyListStore) DeleteUser(userScreenName string)
DeleteUser removes userScreenName's buddy list.
func (*AdjListBuddyListStore) WhoAddedUser ¶ added in v0.3.0
func (store *AdjListBuddyListStore) WhoAddedUser(userScreenName string) []string
WhoAddedUser returns a list of screen names who have userScreenName in their buddy lists.
type BlockedState ¶
type BlockedState int
BlockedState represents the blocked status between two users
const ( // BlockedNo indicates that neither user blocks the other. BlockedNo BlockedState = iota // BlockedA indicates that user A blocks user B. BlockedA // BlockedB indicates that user B blocks user A. BlockedB )
type ChatRegistry ¶
type ChatRegistry struct {
// contains filtered or unexported fields
}
ChatRegistry keeps track of chat rooms. A ChatRegistry is safe for concurrent use by multiple goroutines.
func NewChatRegistry ¶
func NewChatRegistry() *ChatRegistry
NewChatRegistry creates a new instance of ChatRegistry
func (*ChatRegistry) Register ¶
func (c *ChatRegistry) Register(chatRoom ChatRoom, value any)
Register adds a chat room to the registry and associates an arbitrary value with the room.
func (*ChatRegistry) Remove ¶
func (c *ChatRegistry) Remove(cookie string)
Remove removes a chat room and the arbitrary value associated with it.
type ChatRoom ¶
type ChatRoom struct { // Cookie is the unique chat room identifier. Cookie string // CreateTime indicates when the chat room was created. CreateTime time.Time // DetailLevel is the detail level of the chat room. Unclear what this value means. DetailLevel uint8 // Exchange indicates which exchange the chatroom belongs to. Typically, a canned value. Exchange uint16 // InstanceNumber indicates which instance chatroom exists in. Typically, a canned value. InstanceNumber uint16 // Name is the name of the chat room. Name string }
ChatRoom is the representation of a chat room's metadata.
type InMemorySessionManager ¶
type InMemorySessionManager struct {
// contains filtered or unexported fields
}
InMemorySessionManager handles the lifecycle of a user session and provides synchronized message relay between sessions in the session pool. An InMemorySessionManager is safe for concurrent use by multiple goroutines.
func NewInMemorySessionManager ¶
func NewInMemorySessionManager(logger *slog.Logger) *InMemorySessionManager
NewInMemorySessionManager creates a new instance of InMemorySessionManager.
func (*InMemorySessionManager) AddSession ¶
func (s *InMemorySessionManager) AddSession(sessID string, screenName string) *Session
AddSession adds a new session to the pool. It replaces an existing session with a matching screen name, ensuring that each screen name is unique in the pool.
func (*InMemorySessionManager) AllSessions ¶
func (s *InMemorySessionManager) AllSessions() []*Session
AllSessions returns all sessions in the session pool.
func (*InMemorySessionManager) Empty ¶
func (s *InMemorySessionManager) Empty() bool
Empty returns true if the session pool contains 0 sessions.
func (*InMemorySessionManager) RelayToAll ¶
func (s *InMemorySessionManager) RelayToAll(ctx context.Context, msg wire.SNACMessage)
RelayToAll relays a message to all sessions in the session pool.
func (*InMemorySessionManager) RelayToAllExcept ¶
func (s *InMemorySessionManager) RelayToAllExcept(ctx context.Context, except *Session, msg wire.SNACMessage)
RelayToAllExcept relays a message to all session in the pool except for one particular session.
func (*InMemorySessionManager) RelayToScreenName ¶
func (s *InMemorySessionManager) RelayToScreenName(ctx context.Context, screenName string, msg wire.SNACMessage)
RelayToScreenName relays a message to a session with a matching screen name.
func (*InMemorySessionManager) RelayToScreenNames ¶
func (s *InMemorySessionManager) RelayToScreenNames(ctx context.Context, screenNames []string, msg wire.SNACMessage)
RelayToScreenNames relays a message to sessions with matching screenNames.
func (*InMemorySessionManager) RemoveSession ¶
func (s *InMemorySessionManager) RemoveSession(sess *Session)
RemoveSession takes a session out of the session pool.
func (*InMemorySessionManager) RetrieveByScreenName ¶
func (s *InMemorySessionManager) RetrieveByScreenName(screenName string) *Session
RetrieveByScreenName find a session with a matching screen name. Returns nil if session is not found.
func (*InMemorySessionManager) RetrieveSession ¶
func (s *InMemorySessionManager) RetrieveSession(sessionID string) *Session
RetrieveSession finds a session with a matching sessionID. Returns nil if session is not found.
type SQLiteUserStore ¶
type SQLiteUserStore struct {
// contains filtered or unexported fields
}
SQLiteUserStore stores user feedbag (buddy list), profile, and authentication credentials information in a SQLite database.
func NewSQLiteUserStore ¶
func NewSQLiteUserStore(dbFilePath string) (*SQLiteUserStore, error)
NewSQLiteUserStore creates a new instance of SQLiteUserStore. If the database does not already exist, a new one is created with the required schema.
func (SQLiteUserStore) AdjacentUsers ¶
func (f SQLiteUserStore) AdjacentUsers(screenName string) ([]string, error)
AdjacentUsers returns all users who have screenName in their buddy list. Exclude users who are on screenName's block list.
func (SQLiteUserStore) AllUsers ¶
func (f SQLiteUserStore) AllUsers() ([]User, error)
AllUsers returns all stored users. It only populates the User.ScreenName field populated in the returned slice.
func (SQLiteUserStore) BARTRetrieve ¶
func (f SQLiteUserStore) BARTRetrieve(hash []byte) ([]byte, error)
func (SQLiteUserStore) BARTUpsert ¶
func (f SQLiteUserStore) BARTUpsert(itemHash []byte, body []byte) error
func (SQLiteUserStore) BlockedState ¶
func (f SQLiteUserStore) BlockedState(screenNameA, screenNameB string) (BlockedState, error)
BlockedState returns the BlockedState between two users.
func (SQLiteUserStore) Buddies ¶
func (f SQLiteUserStore) Buddies(screenName string) ([]string, error)
Buddies returns all user's buddies. Don't return a buddy if the user has them on their block list.
func (SQLiteUserStore) Feedbag ¶
func (f SQLiteUserStore) Feedbag(screenName string) ([]wire.FeedbagItem, error)
Feedbag fetches the contents of a user's feedbag (buddy list).
func (SQLiteUserStore) FeedbagDelete ¶
func (f SQLiteUserStore) FeedbagDelete(screenName string, items []wire.FeedbagItem) error
FeedbagDelete deletes an entry from a user's feedbag (buddy list).
func (SQLiteUserStore) FeedbagLastModified ¶
func (f SQLiteUserStore) FeedbagLastModified(screenName string) (time.Time, error)
FeedbagLastModified returns the last time a user's feedbag (buddy list) was updated.
func (SQLiteUserStore) FeedbagUpsert ¶
func (f SQLiteUserStore) FeedbagUpsert(screenName string, items []wire.FeedbagItem) error
FeedbagUpsert upserts an entry to a user's feedbag (buddy list). An entry is created if it doesn't already exist, or modified if it already exists.
func (SQLiteUserStore) InsertUser ¶
func (f SQLiteUserStore) InsertUser(u User) error
InsertUser inserts a user to the store. Return ErrDupUser if a user with the same screen name already exists.
func (SQLiteUserStore) Profile ¶
func (f SQLiteUserStore) Profile(screenName string) (string, error)
Profile fetches a user profile. Return empty string if the user does not exist or has no profile.
func (SQLiteUserStore) SetProfile ¶
func (f SQLiteUserStore) SetProfile(screenName string, body string) error
SetProfile sets the text contents of a user's profile.
func (SQLiteUserStore) SetUserPassword ¶ added in v0.3.0
func (f SQLiteUserStore) SetUserPassword(u User) error
SetUserPassword sets the user's password hashes and auth key.
type SessSendStatus ¶
type SessSendStatus int
SessSendStatus is the result of sending a message to a user.
const ( // SessSendOK indicates message was sent to recipient SessSendOK SessSendStatus = iota // SessSendClosed indicates send did not complete because session is closed SessSendClosed // SessQueueFull indicates send failed due to full queue -- client is likely // dead SessQueueFull )
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a user's current session. Unless stated otherwise, all methods may be safely accessed by multiple goroutines.
func NewSession ¶
func NewSession() *Session
NewSession returns a new instance of Session. By default, the user may have up to 1000 pending messages before blocking.
func (*Session) AwayMessage ¶
AwayMessage returns the user's away message.
func (*Session) ChatRoomCookie ¶
ChatRoomCookie gets the chatRoomCookie for the chat room the user is currently in.
func (*Session) Close ¶
func (s *Session) Close()
Close shuts down the session's ability to relay messages. Once invoked, RelayMessage returns SessQueueFull and Closed returns a closed channel. It is not possible to re-open message relaying once closed. It is safe to call from multiple go routines.
func (*Session) Closed ¶
func (s *Session) Closed() <-chan struct{}
Closed blocks until the session is closed.
func (*Session) IncrementWarning ¶
IncrementWarning increments the user's warning level. To decrease, pass a negative increment value.
func (*Session) ReceiveMessage ¶
func (s *Session) ReceiveMessage() chan wire.SNACMessage
ReceiveMessage returns a channel of messages relayed via this session. It may only be read by one consumer. The channel never closes; call this method in a select block along with Closed in order to detect session closure.
func (*Session) RelayMessage ¶
func (s *Session) RelayMessage(msg wire.SNACMessage) SessSendStatus
RelayMessage receives a SNAC message from a user and passes it on asynchronously to the consumer of this session's messages. It returns SessSendStatus to indicate whether the message was successfully sent or not. This method is non-blocking.
func (*Session) ScreenName ¶
ScreenName returns the user's screen name.
func (*Session) SetAwayMessage ¶
SetAwayMessage sets the user's away message.
func (*Session) SetCaps ¶
SetCaps sets capability UUIDs that represent the features the client supports. If set, capability metadata appears in the user info TLV list.
func (*Session) SetChatRoomCookie ¶
SetChatRoomCookie sets the chatRoomCookie for the chat room the user is currently in.
func (*Session) SetInvisible ¶
SetInvisible toggles the user's invisibility status.
func (*Session) SetScreenName ¶
SetScreenName sets the user's screen name.
func (*Session) SetSignonComplete ¶ added in v0.3.0
func (s *Session) SetSignonComplete()
SetSignonComplete indicates that the client has completed the sign-on sequence.
func (*Session) SetSignonTime ¶
SetSignonTime sets the user's sign-ontime.
func (*Session) SignonComplete ¶ added in v0.3.0
SignonComplete indicates whether the client has completed the sign-on sequence.
func (*Session) TLVUserInfo ¶
func (s *Session) TLVUserInfo() wire.TLVUserInfo
TLVUserInfo returns a TLV list containing session information required by multiple SNAC message types that convey user information.
type User ¶
type User struct { ScreenName string `json:"screen_name"` AuthKey string `json:"-"` StrongMD5Pass []byte `json:"-"` WeakMD5Pass []byte `json:"-"` }
User represents an instant messaging user.
func NewStubUser ¶
NewStubUser creates a new user with canned credentials. The default password is "welcome1". This is typically used for development purposes.
func (*User) HashPassword ¶
HashPassword creates a password hash using the MD5 digest algorithm. The hash is stored in the User.StrongMD5Pass field.