hub

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: BSD-3-Clause Imports: 41 Imported by: 1

Documentation

Index

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 DefaultProfiles() map[string]Map

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 Ban added in v0.16.4

type Ban struct {
	Until  time.Time
	Reason string
}

type BasePeer

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

func (*BasePeer) ConnInfo added in v0.16.4

func (p *BasePeer) ConnInfo() *ConnInfo

func (*BasePeer) LocalAddr

func (p *BasePeer) LocalAddr() net.Addr

func (*BasePeer) Name added in v0.16.4

func (p *BasePeer) Name() string

func (*BasePeer) Online added in v0.16.4

func (p *BasePeer) Online() bool

func (*BasePeer) RemoteAddr

func (p *BasePeer) RemoteAddr() net.Addr

func (*BasePeer) SID

func (p *BasePeer) SID() SID

func (*BasePeer) User added in v0.16.4

func (p *BasePeer) User() *User

type Bot added in v0.16.4

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

func (*Bot) Close added in v0.16.4

func (b *Bot) Close() error

func (*Bot) SendGlobal added in v0.16.4

func (b *Bot) SendGlobal(m Message) error

func (*Bot) SendPrivate added in v0.16.4

func (b *Bot) SendPrivate(to Peer, m Message) error

type Broadcaster added in v0.16.4

type Broadcaster interface {
	Peer
	// BroadcastJoinTo is an optimized version of a "peer join" broadcast loop.
	// Implementation gets a chance to pre-compute on-wire encoding of commands for more
	// efficient broadcasts.
	//
	// The simplest implementation is:
	// 	for _, p2 := range peers {
	//		_ = p2.PeersJoin([]Peer{p})
	//	}
	BroadcastJoinTo(peers []Peer)
	// BroadcastUpdateTo is an optimized version of a "peer info update" broadcast loop.
	// Implementation gets a chance to pre-compute on-wire encoding of commands for more
	// efficient broadcasts.
	//
	// The simplest implementation is:
	// 	for _, p2 := range peers {
	//		_ = p2.PeersUpdate([]Peer{p})
	//	}
	BroadcastUpdateTo(peers []Peer)
	// BroadcastLeaveTo is an optimized version of a "peer leave" broadcast loop.
	// Implementation gets a chance to pre-compute on-wire encoding of commands for more
	// efficient broadcasts.
	//
	// The simplest implementation is:
	// 	for _, p2 := range peers {
	//		_ = p2.PeersLeave([]Peer{p})
	//	}
	BroadcastLeaveTo(peers []Peer)
}

type CID added in v0.16.4

type CID = adc.CID

type Command

type Command struct {
	Menu    []string
	Name    string
	Aliases []string
	Short   string
	Long    string
	Require string
	Func    interface{}
	// contains filtered or unexported fields
}

type CommandFunc added in v0.16.4

type CommandFunc = func(p Peer, args string) error

type Config

type Config struct {
	Name             string
	Desc             string
	Addr             string
	Owner            string
	Website          string
	Email            string
	Keyprint         string
	Soft             dc.Software
	MOTD             string
	ChatLog          int
	ChatLogJoin      int
	FallbackEncoding string
	TLS              *tls.Config
}

type ConnInfo added in v0.16.4

type ConnInfo struct {
	Local   net.Addr
	Remote  net.Addr
	Secure  bool
	TLSVers uint16
	ALPN    string
}

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 Dir

type Dir struct {
	Peer Peer
	Path string
}

func (Dir) From

func (f Dir) From() Peer

type DirSearch

type DirSearch struct {
	NameSearch
}

func (DirSearch) Match

func (s DirSearch) Match(r SearchResult) bool

type ErrUnknownProtocol added in v0.16.4

type ErrUnknownProtocol struct {
	Magic  []byte
	Secure bool
}

func (*ErrUnknownProtocol) Error added in v0.16.4

func (e *ErrUnknownProtocol) Error() string

type File

type File struct {
	Peer Peer
	Path string
	Size uint64
	TTH  *TTH
}

func (File) From

func (f File) From() Peer

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 FileType

type FileType int

type Hub

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

func NewHub

func NewHub(conf Config) (*Hub, error)

func (*Hub) AddAddress added in v0.16.4

func (h *Hub) AddAddress(addr string)

func (*Hub) Close added in v0.16.4

func (h *Hub) Close() error

func (*Hub) DeleteUser added in v0.16.4

func (h *Hub) DeleteUser(name string) error

func (*Hub) EachHardBlockedIP added in v0.16.4

func (h *Hub) EachHardBlockedIP(fnc func(ip net.IP) bool)

func (*Hub) HardBlock added in v0.16.4

func (h *Hub) HardBlock(a net.Addr)

func (*Hub) HardBlockIP added in v0.16.4

func (h *Hub) HardBlockIP(ip net.IP)

func (*Hub) HardUnBlockIP added in v0.16.4

func (h *Hub) HardUnBlockIP(ip net.IP)

func (*Hub) HubUser added in v0.16.4

func (h *Hub) HubUser() *Bot

func (*Hub) IsHardBlocked added in v0.16.4

func (h *Hub) IsHardBlocked(a net.Addr) bool

func (*Hub) IsHardBlockedIP added in v0.16.4

func (h *Hub) IsHardBlockedIP(ip net.IP) bool

func (*Hub) IsRegistered

func (h *Hub) IsRegistered(name string) (bool, error)

func (*Hub) ListCommands

func (h *Hub) ListCommands(u *User) []*Command

func (*Hub) ListenAndServe

func (h *Hub) ListenAndServe(addr string) error

func (*Hub) LoadPluginsInDir added in v0.16.4

func (h *Hub) LoadPluginsInDir(dir string) error

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) NewBot added in v0.16.4

func (h *Hub) NewBot(name string, soft dc.Software) (*Bot, error)

func (*Hub) NewRoom

func (h *Hub) NewRoom(name string) (*Room, error)

func (*Hub) OnChat added in v0.16.4

func (h *Hub) OnChat(fnc func(p Peer, m Message) bool)

func (*Hub) OnConnected added in v0.16.4

func (h *Hub) OnConnected(fnc func(c net.Conn) bool)

func (*Hub) OnDisconnected added in v0.16.4

func (h *Hub) OnDisconnected(fnc func(c net.Conn))

func (*Hub) OnJoined added in v0.16.4

func (h *Hub) OnJoined(fnc func(p Peer) bool)

func (*Hub) PeerByName added in v0.16.4

func (h *Hub) PeerByName(name string) Peer

func (*Hub) Peers

func (h *Hub) Peers() []Peer

func (*Hub) Profile added in v0.16.4

func (h *Hub) Profile(id string) *UserProfile

func (*Hub) RegisterCommand added in v0.16.4

func (h *Hub) RegisterCommand(cmd Command)

func (*Hub) RegisterUser

func (h *Hub) RegisterUser(name, pass string) error

func (*Hub) Room

func (h *Hub) Room(name string) *Room

func (*Hub) Rooms added in v0.16.4

func (h *Hub) Rooms() []*Room

func (*Hub) Search

func (h *Hub) Search(req SearchRequest, s Search, peers []Peer)

func (*Hub) SendGlobalChat added in v0.16.4

func (h *Hub) SendGlobalChat(text string)

func (*Hub) Serve

func (h *Hub) Serve(conn net.Conn) error

Serve automatically detects the protocol and start the hub-client handshake.

func (*Hub) ServeADC

func (h *Hub) ServeADC(conn net.Conn, cinfo *ConnInfo) error

func (*Hub) ServeHTTP1

func (h *Hub) ServeHTTP1(conn net.Conn) error

func (*Hub) ServeHTTP2

func (h *Hub) ServeHTTP2(conn net.Conn) error

func (*Hub) ServeIRC

func (h *Hub) ServeIRC(conn net.Conn, cinfo *ConnInfo) error

func (*Hub) ServeNMDC

func (h *Hub) ServeNMDC(conn net.Conn, cinfo *ConnInfo) error

func (*Hub) SetDatabase

func (h *Hub) SetDatabase(db Database)

func (*Hub) Start added in v0.16.4

func (h *Hub) Start() error

func (*Hub) Stats

func (h *Hub) Stats() Stats

func (*Hub) UpdateUser added in v0.16.4

func (h *Hub) UpdateUser(name string, fnc func(u *UserRecord) (bool, error)) error

type Map added in v0.16.4

type Map map[string]interface{}

func (Map) Clone added in v0.16.4

func (m Map) Clone() Map

type Message

type Message struct {
	Time time.Time
	Name string
	Text string
	Me   bool
}

type NameSearch

type NameSearch struct {
	And []string
	Not []string
}

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(peers []Peer) error
	// PeersUpdate sends a set of "peer info update" events to this peer.
	PeersUpdate(peers []Peer) error
	// PeersLeave sends a set of "peer leave" events to this peer.
	PeersLeave(peers []Peer) 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 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 ProfileDatabase interface {
	GetProfile(id string) (Map, error)
	PutProfile(id string, m Map) error
	DelProfile(id string) error
	ListProfiles() ([]string, error)
}

type RawCmd added in v0.16.4

type RawCmd string

type Room

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

func (*Room) InRoom

func (r *Room) InRoom(p Peer) bool

func (*Room) Join

func (r *Room) Join(p Peer)

func (*Room) Leave

func (r *Room) Leave(p Peer)

func (*Room) Name

func (r *Room) Name() string

func (*Room) Peers

func (r *Room) Peers() []Peer

func (*Room) ReplayChat

func (r *Room) ReplayChat(to Peer, n int)

func (*Room) SID

func (r *Room) SID() SID

func (*Room) SendChat

func (r *Room) SendChat(from Peer, m Message)

func (*Room) Users

func (r *Room) Users() int

type SID

type SID = adc.SID
type Search interface {
	Peer() Peer
	SendResult(r SearchResult) error
	Close() error
}

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"`
	Share    uint64      `json:"share"`               // MB
	MaxShare uint64      `json:"max-share,omitempty"` // MB
	Enc      string      `json:"encoding,omitempty"`
	Soft     dc.Software `json:"soft"`
	Uptime   uint64      `json:"uptime,omitempty"`
	Keyprint string      `json:"-"`
}

func (*Stats) DefaultAddr

func (st *Stats) DefaultAddr() string

type TTH

type TTH = tiger.Hash

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) BanUntil added in v0.16.4

func (u *User) BanUntil(t time.Time, reason string)

func (*User) Has added in v0.16.4

func (u *User) Has(flag string) bool

func (*User) HasPerm added in v0.16.4

func (u *User) HasPerm(perm string) bool

func (*User) IsBanned added in v0.16.4

func (u *User) IsBanned() *Ban

func (*User) IsOwner added in v0.16.4

func (u *User) IsOwner() bool

func (*User) Name

func (u *User) Name() string

func (*User) Profile added in v0.16.4

func (u *User) Profile() *UserProfile

func (*User) SetName added in v0.16.4

func (u *User) SetName(name string)

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 UserInfo added in v0.16.4

type UserInfo struct {
	Name           string
	Kind           UserKind
	App            dc.Software
	HubsNormal     int
	HubsRegistered int
	HubsOperator   int
	Slots          int
	Share          uint64
	Email          string
	IPv4           bool
	IPv6           bool
	TLS            bool
}

type UserKind added in v0.16.4

type UserKind int

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

type UserRecord struct {
	Name    string
	Pass    string
	Profile string
}

type Version added in v0.16.4

type Version struct {
	Major int
	Minor int
	Patch int
	Rev   string
}

func (Version) String added in v0.16.4

func (v Version) String() string

func (Version) Vers3 added in v0.16.4

func (v Version) Vers3() string

Directories

Path Synopsis
plugins
all
lua
tor module

Jump to

Keyboard shortcuts

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