Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultProfiles() map[string]Map
- func RegisterPlugin(p Plugin)
- type Ban
- 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) DeleteUser(name string) error
- func (h *Hub) EachHardBlockedIP(fnc func(ip net.IP) bool)
- 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) 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) NewBot(name string, soft dc.Software) (*Bot, error)
- func (h *Hub) NewRoom(name string) (*Room, error)
- func (h *Hub) OnChat(fnc func(p Peer, m Message) bool)
- func (h *Hub) OnConnected(fnc func(c net.Conn) bool)
- func (h *Hub) OnDisconnected(fnc func(c net.Conn))
- func (h *Hub) OnJoined(fnc func(p Peer) bool)
- 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) Search(req SearchRequest, s Search, peers []Peer)
- func (h *Hub) SendGlobalChat(text string)
- 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) 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 PeersJoinEvent
- type PeersLeaveEvent
- type PeersUpdateEvent
- type Plugin
- type ProfileDatabase
- type RawCmd
- type Room
- 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) IsOwner() 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) ID() string
- func (p *UserProfile) IsOwner() bool
- func (p *UserProfile) Parent() *UserProfile
- func (p *UserProfile) SetParent(par *UserProfile) *UserProfile
- type UserRecord
- type Version
Constants ¶
View Source
const ( PermRoomsJoin = "rooms.join" PermRoomsList = "rooms.list" PermBroadcast = "hub.broadcast" PermDrop = "user.drop" PermIP = "user.ip" PermBanIP = "ban.ip" )
View Source
const ( UserNormal = UserKind(iota) UserHub UserBot )
View Source
const ( PermOwner = "owner" ProfileParent = "parent" )
View Source
const ( ProfileNameRoot = "root" ProfileNameRegistered = "user" ProfileNameOperator = "op" ProfileNameGuest = "guest" )
View Source
const ( FlagOpIcon = "icon.op" FlagRegIcon = "icon.reg" )
View Source
const ( FileTypeAny = FileType(0) FileTypePicture = FileType(1 << iota) FileTypeAudio FileTypeVideo FileTypeCompressed FileTypeDocuments FileTypeExecutable )
View Source
const HTTPInfoPathV0 = "/api/v0/hubinfo.json"
Variables ¶
View Source
var ( ErrUserRegDisabled = errors.New("user registration is disabled") ErrUserNotFound = errors.New("user does not exist") ErrNameTaken = errors.New("user name already taken") )
View Source
var (
ErrRoomExists = errors.New("room already exists")
)
Functions ¶
func DefaultProfiles ¶ added in v0.16.4
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.
Types ¶
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
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) DeleteUser ¶ added in v0.16.4
func (*Hub) EachHardBlockedIP ¶ added in v0.16.4
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) OnDisconnected ¶ added in v0.16.4
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) SendGlobalChat ¶ added in v0.16.4
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
// 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 Room ¶
type Room struct {
// contains filtered or unexported fields
}
func (*Room) ReplayChat ¶
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"`
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 dc.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) 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) 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
type UserRecord ¶ added in v0.16.4
Source Files
¶
Click to show internal directories.
Click to hide internal directories.