Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultProfiles() map[string]Map
- func IsBot(p Peer) bool
- func NMDCUserInfo(p Peer) nmdcp.MyINFO
- func RegisterPlugin(p Plugin)
- func ToNMDCChatMsg(from Peer, msg Message) *nmdcp.ChatMessage
- type Ban
- type BanDatabase
- type BanKey
- type BasePeer
- type Bot
- type CID
- type Command
- type CommandFunc
- type Config
- type ConnInfo
- type Database
- type Dir
- type DirSearch
- type ErrUnknownProtocol
- type File
- type FileSearch
- type FileType
- type Hub
- func (h *Hub) AddAddress(addr string)
- func (h *Hub) Close() error
- func (h *Hub) ConfigKeys() []string
- func (h *Hub) DeleteUser(name string) error
- func (h *Hub) EachHardBlockedIP(fnc func(ip net.IP) bool)
- func (h *Hub) GetConfig(key string) (interface{}, bool)
- func (h *Hub) GetConfigBool(key string) (bool, bool)
- func (h *Hub) GetConfigFloat(key string) (float64, bool)
- func (h *Hub) GetConfigInt(key string) (int64, bool)
- func (h *Hub) GetConfigString(key string) (string, bool)
- func (h *Hub) GetConfigUint(key string) (uint64, bool)
- func (h *Hub) GlobalChatRoom() *Room
- func (h *Hub) HardBlock(a net.Addr)
- func (h *Hub) HardBlockIP(ip net.IP)
- func (h *Hub) HardUnBlockIP(ip net.IP)
- func (h *Hub) HubUser() *Bot
- func (h *Hub) IsHardBlocked(a net.Addr) bool
- func (h *Hub) IsHardBlockedIP(ip net.IP) bool
- func (h *Hub) IsPrivate() bool
- func (h *Hub) IsRegistered(name string) (bool, error)
- func (h *Hub) ListCommands(u *User) []*Command
- func (h *Hub) ListenAndServe(addr string) error
- func (h *Hub) LoadPluginsInDir(dir string) error
- func (h *Hub) Log(args ...interface{})
- func (h *Hub) Logf(format string, args ...interface{})
- func (h *Hub) MergeConfig(m Map)
- func (h *Hub) MergeConfigPath(path string, m Map)
- func (h *Hub) NewBot(name string, soft types.Software) (*Bot, error)
- func (h *Hub) NewBotDesc(name, desc, email string, soft types.Software) (*Bot, error)
- func (h *Hub) NewPermRoom(name string, perm string) (*Room, error)
- func (h *Hub) NewPrivateRoom(name string) (*Room, error)
- func (h *Hub) NewRoom(name string) (*Room, error)
- func (h *Hub) OnChat(fnc func(r *Room, p Peer, m Message) bool)
- func (h *Hub) OnConnected(fnc func(c net.Conn) bool)
- func (h *Hub) OnConnectedIP4(fnc func(c net.Conn, ip net.IP) bool)
- func (h *Hub) OnConnectedIP6(fnc func(c net.Conn, ip net.IP) bool)
- func (h *Hub) OnDisconnected(fnc func(c net.Conn))
- func (h *Hub) OnGlobalChat(fnc func(p Peer, m Message) bool)
- func (h *Hub) OnJoined(fnc func(p Peer) bool)
- func (h *Hub) OnLeave(fnc func(p Peer))
- func (h *Hub) OnPM(fnc func(from, to Peer, m Message) bool)
- func (h *Hub) OnPermJoined(perm string, fnc func(p Peer) bool)
- func (h *Hub) OnPermLeave(perm string, fnc func(p Peer))
- func (h *Hub) OpLog(args ...interface{})
- func (h *Hub) OpLogf(format string, args ...interface{})
- func (h *Hub) PeerByName(name string) Peer
- func (h *Hub) Peers() []Peer
- func (h *Hub) Profile(id string) *UserProfile
- func (h *Hub) RegisterCommand(cmd Command)
- func (h *Hub) RegisterUser(name, pass string) error
- func (h *Hub) Room(name string) *Room
- func (h *Hub) Rooms() []*Room
- func (h *Hub) RoomsFor(p Peer) []*Room
- func (h *Hub) Search(req SearchRequest, s Search, peers []Peer)
- func (h *Hub) SendGlobalChat(text string)
- func (h *Hub) SendNMDCTo(p Peer, msgs ...nmdcp.Message) error
- func (h *Hub) Serve(conn net.Conn) error
- func (h *Hub) ServeADC(conn net.Conn, cinfo *ConnInfo) error
- func (h *Hub) ServeHTTP1(conn net.Conn) error
- func (h *Hub) ServeHTTP2(conn net.Conn) error
- func (h *Hub) ServeIRC(conn net.Conn, cinfo *ConnInfo) error
- func (h *Hub) ServeNMDC(conn net.Conn, cinfo *ConnInfo) error
- func (h *Hub) SetConfig(key string, val interface{})
- func (h *Hub) SetConfigBool(key string, val bool)
- func (h *Hub) SetConfigFloat(key string, val float64)
- func (h *Hub) SetConfigInt(key string, val int64)
- func (h *Hub) SetConfigString(key string, val string)
- func (h *Hub) SetConfigUint(key string, val uint64)
- func (h *Hub) SetDatabase(db Database)
- func (h *Hub) Start() error
- func (h *Hub) Stats() Stats
- func (h *Hub) UpdateUser(name string, fnc func(u *UserRecord) (bool, error)) error
- func (h *Hub) Uptime() time.Duration
- type Map
- type Message
- type NameSearch
- type Peer
- type PeerTopic
- type PeersJoinEvent
- type PeersLeaveEvent
- type PeersUpdateEvent
- type Plugin
- type ProfileDatabase
- type RawCmd
- type ReleaseInfo
- type Room
- func (r *Room) CanJoin(p Peer) bool
- func (r *Room) InRoom(p Peer) bool
- func (r *Room) IsPrivate() bool
- func (r *Room) Join(p Peer)
- func (r *Room) Leave(p Peer)
- func (r *Room) Name() string
- func (r *Room) Peers() []Peer
- func (r *Room) ReplayChat(to Peer, n int)
- func (r *Room) SID() SID
- func (r *Room) SendChat(from Peer, m Message)
- func (r *Room) Users() int
- type SID
- type Search
- type SearchRequest
- type SearchResult
- type Stats
- type TTH
- type TTHSearch
- type User
- func (u *User) BanUntil(t time.Time, reason string)
- func (u *User) Has(flag string) bool
- func (u *User) HasPerm(perm string) bool
- func (u *User) IsBanned() *Ban
- func (u *User) IsOp() bool
- func (u *User) IsOwner() bool
- func (u *User) IsRegistered() bool
- func (u *User) Name() string
- func (u *User) Profile() *UserProfile
- func (u *User) SetName(name string)
- func (u *User) SetProfile(p *UserProfile)
- type UserDatabase
- type UserInfo
- type UserKind
- type UserProfile
- func (p *UserProfile) Get(key string) (interface{}, bool)
- func (p *UserProfile) GetBool(key string) bool
- func (p *UserProfile) GetString(key string) string
- func (p *UserProfile) Has(flag string) bool
- func (p *UserProfile) HasParent(id string) bool
- func (p *UserProfile) ID() string
- func (p *UserProfile) IsOwner() bool
- func (p *UserProfile) Parent() *UserProfile
- func (p *UserProfile) SetParent(par *UserProfile) *UserProfile
- type UserRecord
- type Version
Constants ¶
const ( PermRoomsJoin = "rooms.join" PermRoomsNew = "rooms.new" PermRoomsList = "rooms.list" PermRoomsOpChat = "rooms.opchat" PermBroadcast = "hub.broadcast" PermConfigWrite = "config.write" PermConfigRead = "config.read" PermTopic = "hub.topic" PermDrop = "user.drop" PermDropAll = "user.drop_all" PermRedirect = "user.redirect" PermRedirectAll = "user.redirect_all" PermRegister = "user.register" PermRegisterProfile = "user.register_profile" PermIP = "user.ip" PermBanIP = "ban.ip" )
const ( ConfigHubName = "hub.name" ConfigHubDesc = "hub.desc" ConfigHubTopic = "hub.topic" ConfigHubOwner = "hub.owner" ConfigHubWebsite = "hub.website" ConfigHubEmail = "hub.email" ConfigHubMOTD = "hub.motd" ConfigHubPrivate = "hub.private" )
const ( ConfigZlibLevel = "zlib.level" ConfigNMDCRedirectTLS = "nmdc.redirect.tls" ConfigNMDCRedirectADC = "nmdc.redirect.adc" ConfigADCRedirectTLS = "adc.redirect.tls" )
const ( UserNormal = UserKind(iota) UserHub UserBot )
const ( PermOwner = "owner" ProfileParent = "parent" )
const ( ProfileNameRoot = "root" ProfileNameRegistered = "user" ProfileNameOperator = "op" ProfileNameGuest = "guest" )
const ( FlagOpIcon = "icon.op" FlagRegIcon = "icon.reg" )
const ( FileTypeAny = FileType(0) FileTypePicture = FileType(1 << iota) FileTypeAudio FileTypeVideo FileTypeCompressed FileTypeDocuments FileTypeExecutable )
const HTTPInfoPathV0 = "/api/v0/hubinfo.json"
Variables ¶
var ( ErrRoomExists = errors.New("room already exists") ErrCantJoinRoom = errors.New("cannot join the room") )
Functions ¶
func DefaultProfiles ¶ added in v0.16.4
func NMDCUserInfo ¶ added in v0.20.0
func RegisterPlugin ¶ added in v0.16.4
func RegisterPlugin(p Plugin)
RegisterPlugin should be called to register a new hub plugin. When the hub is started, p.Init will be called to associate the plugin with a hub.
This function should be called in the plugin's init() function.
func ToNMDCChatMsg ¶ added in v0.20.0
func ToNMDCChatMsg(from Peer, msg Message) *nmdcp.ChatMessage
Types ¶
type BanDatabase ¶ added in v0.20.0
type BasePeer ¶
type BasePeer struct {
// contains filtered or unexported fields
}
func (*BasePeer) RemoteAddr ¶
type Bot ¶ added in v0.16.4
type Bot struct {
// contains filtered or unexported fields
}
func (*Bot) SendGlobal ¶ added in v0.16.4
type CommandFunc ¶ added in v0.16.4
type Database ¶
type Database interface { UserDatabase ProfileDatabase BanDatabase Close() error }
func NewDatabase ¶ added in v0.16.4
func NewDatabase() Database
NewDatabase creates an in-memory users database.
type DirSearch ¶
type DirSearch struct {
NameSearch
}
func (DirSearch) Match ¶
func (s DirSearch) Match(r SearchResult) bool
type ErrUnknownProtocol ¶ added in v0.16.4
func (*ErrUnknownProtocol) Error ¶ added in v0.16.4
func (e *ErrUnknownProtocol) Error() string
type FileSearch ¶
type FileSearch struct { NameSearch Ext []string NoExt []string FileType FileType MinSize uint64 MaxSize uint64 }
func (FileSearch) Match ¶
func (s FileSearch) Match(r SearchResult) bool
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
func (*Hub) AddAddress ¶ added in v0.16.4
func (*Hub) ConfigKeys ¶ added in v0.20.0
func (*Hub) DeleteUser ¶ added in v0.16.4
func (*Hub) EachHardBlockedIP ¶ added in v0.16.4
func (*Hub) GetConfigFloat ¶ added in v0.20.0
func (*Hub) GetConfigString ¶ added in v0.20.0
func (*Hub) GlobalChatRoom ¶ added in v0.25.0
GlobalChatRoom returns a global chat room that all users join by default when entering the hub.
func (*Hub) HardBlockIP ¶ added in v0.16.4
func (*Hub) HardUnBlockIP ¶ added in v0.16.4
func (*Hub) ListCommands ¶
func (*Hub) ListenAndServe ¶
func (*Hub) LoadPluginsInDir ¶ added in v0.16.4
LoadPluginsInDir loads all plugins in a specified directory. Should be called before Start.
Details about building Go plugins can be found here: https://golang.org/pkg/plugin/
func (*Hub) MergeConfig ¶ added in v0.20.0
func (*Hub) MergeConfigPath ¶ added in v0.20.0
func (*Hub) NewBotDesc ¶ added in v0.20.0
func (*Hub) NewPermRoom ¶ added in v0.25.0
NewPermRoom creates a new private room that can be accessed by anyone with a given permission.
func (*Hub) NewPrivateRoom ¶ added in v0.25.0
NewPrivateRoom creates a new private room. It cannot be entered by anyone except the owner. It's the caller's responsibility to add users to this kind of room.
func (*Hub) OnChat ¶ added in v0.16.4
OnChat is triggered when the message is sent in any of the chat rooms. The function returns a flag if a message should be accepted or not.
func (*Hub) OnConnected ¶ added in v0.16.4
OnConnected registers a trigger for a moment when a new connection is accepted, but before the protocol detection. The function returns a flag indicating if a connection should be accepted or not.
func (*Hub) OnConnectedIP4 ¶ added in v0.25.0
OnConnectedIP4 registers a trigger for a moment when a new connection from IPv4 is accepted, but before the protocol detection. The function returns a flag indicating if a connection should be accepted or not.
func (*Hub) OnConnectedIP6 ¶ added in v0.25.0
OnConnectedIP6 registers a trigger for a moment when a new connection from IPv6 is accepted, but before the protocol detection. The function returns a flag indicating if a connection should be accepted or not.
func (*Hub) OnDisconnected ¶ added in v0.16.4
OnDisconnected registers a trigger for a moment when the connection is closed.
func (*Hub) OnGlobalChat ¶ added in v0.25.0
OnGlobalChat is triggered when the message is sent in the global chat. The function returns a flag if a message should be accepted or not.
func (*Hub) OnJoined ¶ added in v0.16.4
OnJoined is triggered when the peer successfully joins the hub, after all the checks and right before the client event loop. The function returns a flag if a peer should be accepted or not.
func (*Hub) OnLeave ¶ added in v0.20.0
OnLeave is triggered when the peer disconnects from the hub, after he was unregistered from the users list.
func (*Hub) OnPM ¶ added in v0.25.0
OnPM is triggered when the private message is sent through the hub. The function returns a flag if a message should be accepted or not.
func (*Hub) OnPermJoined ¶ added in v0.25.0
OnPermJoined is an analog of OnJoined, but triggers only when a user with a specified permission joins.
func (*Hub) OnPermLeave ¶ added in v0.25.0
OnPermLeave is an analog of OnLeave, but triggers only when a user with a specified permission leaves.
func (*Hub) PeerByName ¶ added in v0.16.4
func (*Hub) Profile ¶ added in v0.16.4
func (h *Hub) Profile(id string) *UserProfile
func (*Hub) RegisterCommand ¶ added in v0.16.4
func (*Hub) RegisterUser ¶
func (*Hub) Room ¶
Room finds a room with a given name. It returns nil if room doesn't exist. This function won't be able to retrieve the global chat. See GlobalChatRoom for this.
func (*Hub) Rooms ¶ added in v0.16.4
Rooms returns a list of all rooms that exist on the hub. It won't list the global chat. This function returns all rooms regardless of user's permissions. Use RoomsFor to get a filtered list.
func (*Hub) RoomsFor ¶ added in v0.25.0
RoomsFor returns a list of all rooms that are accessible by the peer. It won't list the global chat.
func (*Hub) SendGlobalChat ¶ added in v0.16.4
func (*Hub) SendNMDCTo ¶ added in v0.20.0
func (*Hub) SetConfigBool ¶ added in v0.20.0
func (*Hub) SetConfigFloat ¶ added in v0.20.0
func (*Hub) SetConfigInt ¶ added in v0.20.0
func (*Hub) SetConfigString ¶ added in v0.20.0
func (*Hub) SetConfigUint ¶ added in v0.20.0
func (*Hub) SetDatabase ¶
func (*Hub) UpdateUser ¶ added in v0.16.4
type NameSearch ¶
func (NameSearch) Match ¶
func (f NameSearch) Match(r SearchResult) bool
func (NameSearch) MatchName ¶
func (f NameSearch) MatchName(name string) bool
type Peer ¶
type Peer interface { // Close the peer's connection. Close() error // ConnInfo returns a connection information for this peer. // The returned value should not be changed. ConnInfo() *ConnInfo // User returns a user associated with this peer. It may be nil. User() *User // Online flag for this peer. Online() bool // Searchable checks if this peer accepts search requests. Searchable() bool // SID returns a session ID of this peer. SID() SID // Name returns peer's user name. Name() string // UserInfo returns a snapshot of a user info. UserInfo() UserInfo // PeersJoin sends a set of "peer join" events to this peer. PeersJoin(e *PeersJoinEvent) error // PeersUpdate sends a set of "peer info update" events to this peer. PeersUpdate(e *PeersUpdateEvent) error // PeersLeave sends a set of "peer leave" events to this peer. PeersLeave(e *PeersLeaveEvent) error // PrivateMsg sends a private message for this peer. PrivateMsg(from Peer, m Message) error // HubChatMsg sends a global message from the hub. HubChatMsg(m Message) error // JoinRoom sends a "room join" event for this peer. JoinRoom(room *Room) error // ChatMsg sends a chat message from a specific room to this peer. ChatMsg(room *Room, from Peer, m Message) error // LeaveRoom sends a "room leave" event for this peer. LeaveRoom(room *Room) error // ConnectTo sends a connection request to this peer. ConnectTo(peer Peer, addr string, token string, secure bool) error // RevConnectTo sends a reverse connection request to this peer. RevConnectTo(peer Peer, token string, secure bool) error // Search sends a search request to this peer. Search(ctx context.Context, req SearchRequest, out Search) error // Redirect the peer to a different hub or address. Redirect(addr string) error // contains filtered or unexported methods }
type PeersJoinEvent ¶ added in v0.18.0
type PeersJoinEvent struct { Peers []Peer // contains filtered or unexported fields }
type PeersLeaveEvent ¶ added in v0.18.0
type PeersLeaveEvent struct { Peers []Peer // contains filtered or unexported fields }
type PeersUpdateEvent ¶ added in v0.18.0
type PeersUpdateEvent struct { Peers []Peer // contains filtered or unexported fields }
type Plugin ¶ added in v0.16.4
type Plugin interface { // Name is a unique name of a plugin. Name() string // Version returns a plugin version. Version() Version // Init the plugin for a given hub. The plugin should save the reference to // the hub to be able to call methods on it. Init(h *Hub, path string) error // Close shuts down a plugin. Close() error }
type ProfileDatabase ¶ added in v0.16.4
type ReleaseInfo ¶ added in v0.25.0
ReleaseInfo contains an information about a specific software release.
func CheckForUpdates ¶ added in v0.25.0
func CheckForUpdates(ctx context.Context, force bool) (*ReleaseInfo, error)
CheckForUpdates fetches the latest release info and returns it, if it's different from the current version. The method does its own caching so it is safe to call it as frequently as necessary. Force flag can be used to bypass the cache.
type Room ¶
type Room struct {
// contains filtered or unexported fields
}
func (*Room) Join ¶
Join adds the peer to the room. It will not run any additional checks. See CanJoin for this.
func (*Room) ReplayChat ¶
ReplayChat replays the chat log from this room to a given peer.
type SearchRequest ¶
type SearchRequest interface { Match(r SearchResult) bool // contains filtered or unexported methods }
type SearchResult ¶
type SearchResult interface { From() Peer // contains filtered or unexported methods }
type Stats ¶
type Stats struct { Name string `json:"name"` Desc string `json:"desc,omitempty"` Addr []string `json:"addr,omitempty"` Private bool `json:"private,omitempty"` Icon string `json:"icon,omitempty"` Owner string `json:"owner,omitempty"` Website string `json:"website,omitempty"` Email string `json:"email,omitempty"` Users int `json:"users"` MaxUsers int `json:"max-users,omitempty"` Enc string `json:"encoding,omitempty"` Soft types.Software `json:"soft"` Uptime uint64 `json:"uptime,omitempty"` Keyprint string `json:"-"` }
func (*Stats) DefaultAddr ¶
type TTHSearch ¶
type TTHSearch TTH
func (TTHSearch) Match ¶
func (h TTHSearch) Match(r SearchResult) bool
type User ¶
type User struct {
// contains filtered or unexported fields
}
func (*User) IsRegistered ¶ added in v0.20.0
func (*User) Profile ¶ added in v0.16.4
func (u *User) Profile() *UserProfile
func (*User) SetProfile ¶ added in v0.16.4
func (u *User) SetProfile(p *UserProfile)
type UserDatabase ¶
type UserDatabase interface { IsRegistered(name string) (bool, error) GetUser(name string) (*UserRecord, error) CreateUser(rec UserRecord) error DeleteUser(name string) error ListUsers() ([]UserRecord, error) UpdateUser(name string, fnc func(u *UserRecord) (bool, error)) error }
type UserProfile ¶ added in v0.16.4
type UserProfile struct {
// contains filtered or unexported fields
}
func (*UserProfile) Get ¶ added in v0.16.4
func (p *UserProfile) Get(key string) (interface{}, bool)
func (*UserProfile) GetBool ¶ added in v0.16.4
func (p *UserProfile) GetBool(key string) bool
func (*UserProfile) GetString ¶ added in v0.16.4
func (p *UserProfile) GetString(key string) string
func (*UserProfile) Has ¶ added in v0.16.4
func (p *UserProfile) Has(flag string) bool
func (*UserProfile) HasParent ¶ added in v0.20.0
func (p *UserProfile) HasParent(id string) bool
func (*UserProfile) ID ¶ added in v0.16.4
func (p *UserProfile) ID() string
func (*UserProfile) IsOwner ¶ added in v0.16.4
func (p *UserProfile) IsOwner() bool
func (*UserProfile) Parent ¶ added in v0.16.4
func (p *UserProfile) Parent() *UserProfile
func (*UserProfile) SetParent ¶ added in v0.16.4
func (p *UserProfile) SetParent(par *UserProfile) *UserProfile