Documentation ¶
Overview ¶
Database functions. Database is the file with line-bundles: msgid:base64 encoded msg. File db.idx is created and mantained automatically. There is also points.txt, db of users.
Simple log system.
Index ¶
- Variables
- func FileLines(path string, fn func(string) bool) error
- func InitLog()
- func IsEcho(e string) bool
- func IsEmptySubject(s string) bool
- func IsMsgId(id string) bool
- func IsPassword(u string) bool
- func IsPrivate(e string) bool
- func IsSubject(s string) bool
- func IsUsername(u string) bool
- func MakeSecret(msg string) string
- func MsgId(msg string) string
- func OpenLog(trace io.Writer, info io.Writer, error io.Writer)
- type DB
- func (db *DB) Access(info *MsgInfo, user *User) bool
- func (db *DB) Blacklist(m *Msg) error
- func (db *DB) BundlePath() string
- func (db *DB) CreateIndex() error
- func (db *DB) Echoes(names []string, q Query) []*Echo
- func (db *DB) Edit(m *Msg) error
- func (db *DB) Exists(Id string) *MsgInfo
- func (db *DB) Get(Id string) *Msg
- func (db *DB) GetBundle(Id string) string
- func (db *DB) GetBundleInfo(Id string) (string, *MsgInfo)
- func (db *DB) GetFast(Id string) *Msg
- func (db *DB) GetTopics(mi []*MsgInfo) map[string][]string
- func (db *DB) IndexPath() string
- func (db *DB) LoadIndex() error
- func (db *DB) Lock() bool
- func (db *DB) LockPath() string
- func (db *DB) Lookup(Id string) *MsgInfo
- func (db *DB) LookupFast(Id string, bl bool) *MsgInfo
- func (db *DB) LookupIDS(Ids []string) []*MsgInfo
- func (db *DB) Match(info *MsgInfo, r Query) bool
- func (db *DB) SelectIDS(r Query) []string
- func (db *DB) Store(m *Msg) error
- func (db *DB) Unlock()
- type EDB
- type Echo
- type Index
- type Msg
- type MsgInfo
- type Node
- func (n *Node) Fetch(db *DB, Echolist []string, limit int) error
- func (n *Node) Fetcher(db *DB, Echo string, limit int, wait *sync.WaitGroup, cond *sync.Cond)
- func (n *Node) IsFeature(f string) bool
- func (n *Node) List() ([]string, error)
- func (n *Node) Post(pauth string, msg string) error
- func (n *Node) Send(pauth string, msg string) error
- func (n *Node) Store(db *DB, ids []string) error
- type Query
- type Tags
- type UDB
- func (db *UDB) Access(Secret string) bool
- func (db *UDB) Add(Name string, Mail string, Passwd string) error
- func (db *UDB) Auth(User string, Passwd string) bool
- func (db *UDB) Edit(u *User) error
- func (db *UDB) Id(Secret string) int32
- func (db *UDB) LoadUsers() error
- func (db *UDB) Name(Secret string) string
- func (db *UDB) Secret(User string) string
- func (db *UDB) UserInfo(Secret string) *User
- func (db *UDB) UserInfoId(id int32) *User
- func (db *UDB) UserInfoName(name string) *User
- type User
Constants ¶
This section is empty.
Variables ¶
var MaxConnections = 6
Do not run more then MaxConnections goroutines in the same time
Functions ¶
func FileLines ¶
Utility to pass all lines of file (path) to fn(line). Stops on EOF or fn returns false.
func IsEmptySubject ¶
Check if subject is empty string Used when validate msg from points
func IsPrivate ¶
Check if Echoarea is private area This is ii-go extension, echoareas that has "." prefix are for private messaging. Those areas can be fetched only with /u/point/auth/u/e/ scheme
func MakeSecret ¶
Make secret from string. String is something like id + user + password
Types ¶
type DB ¶
type DB struct { Path string Idx Index Sync sync.RWMutex IdxSync sync.RWMutex Name string LockDepth int32 }
Database object. Returns by OpenDB. Idx: Index structure (like dictionary). Name: database name, 'db' by default. Sync: used to syncronize access to DB from goroutines (many readers, one writer). IdxSync: same, but for Index. LockDepth: used for recursive file lock, to avoid conflict between ii-tool and ii-node.
func OpenDB ¶
Opens DB and returns pointer to DB object. path is the path to db. By default it is ./db Index will be named as path + ".idx"
func (*DB) Blacklist ¶
Blacklist decoded message. Blacklisting is adding special tag: access/blacklist and Edit operation to store it in DB. While loading index, blacklisted messages are marked by negative Off field (-1).
func (*DB) Echoes ¶
Make query and select Echoes Returns: slice of pointers to Echo. names: if not empty, lookup only in theese echoareas Does lock. Load/create index if needed. Echoes sorted by date of last messages.
func (*DB) Edit ¶
Store decoded message in database even it is exists. So, it's like Edit operation. While index loaded, it got last version of message data.
func (*DB) Get ¶
Get decoded message from db by message id. Does lock. Loads/create index if needed.
func (*DB) GetBundle ¶
Get bundle line by message id from db. Does lock! Loads/create index if needed.
func (*DB) GetFast ¶
Fast varian (w/o locking) of Get. Get decoded message from db by message id. Does NOT lock! Loads/create index if needed.
func (*DB) GetTopics ¶
Internal function. Get slice of MsgInfo pointers and create information about topics. Information returns in form of: [topicid][]ids topic id is the msg id of most old parent in echo ids - is the messages in this topic
func (*DB) LoadIndex ¶
Loads index. If index doesent exists, create and load it. If index was changed, reread tail. This function does lock.
func (*DB) Lock ¶
Recursive file lock. Used to avoid conflicts between ii-tool and ii-node. Uses mkdir as atomic operation. Note: dirs created as db.LockPath() 16 sec is limit.
func (*DB) Lookup ¶
Lookup message in index. Do not search blacklisted messages. Creates/load index if needed. Returns MsgInfo pointer. Does lock!
func (*DB) LookupFast ¶
Lookup variant, but without locking. Useful if caller do locking logic himself.
func (*DB) LookupIDS ¶
Lookup messages in index. Gets: slice of message ids to get. Returns slice of MsgInfo pointers. Does lock!
func (*DB) SelectIDS ¶
Make query and retuen ids as slice of strings. Does lock. Can create/load index if needed. r: request, see Query
type EDB ¶
Echo database entry Holds echo descriptions in Info hash. List - names of echoareas.
func LoadEcholist ¶
Loads echolist database and returns pointer to EDB Supposed to be called only once
type Echo ¶
Used to get information about echoarea Count: number of messages Topics: number of topics Last: last MsgInfo Msg: last message pointer
type Index ¶
Index object. Holds List and Hash for all MsgInfo entries FileSize is used to auto reread new entries if it has changed by someone.
type Msg ¶
type Msg struct { MsgId string Tags Tags Echo string Date int64 From string Addr string To string Subj string Text string }
Decoded message. Has all atrributes of message including Tags.
func DecodeBundle ¶
Decode bundle line in msgid:message format or just message Returns pointer to decoded Msg or nil, error if fail. Can parse URL safe and STD BASE64. This function does NOT add ii/ok tag and does NOT change Date
func DecodeMsgline ¶
Decode message from point sent with /u/point scheme. Try to use URL save and STD base64. Returns pointrt to decoded Msg or nil (and error) Note: This function adds "ii/ok" to Tags and set Date field with UTC Unix time.
type MsgInfo ¶
type MsgInfo struct { Num int Id string Echo string To string Off int64 Repto string From string Topic string }
This is index entry. Information about message that is loaded in memory. So, the index could not be very huge. Num: sequence number. Id: MsgId Echo: Echoarea To, From, Repto: message attributes Off: offset to bundle-line in database (in bytes)
type Node ¶
Node object. Use Connect to create it. Host: url node Features: extensions map Force: force sync even last message is not new
func (*Node) Fetch ¶
This is Fetcher master function. It makes fetch from node and run goroutines in parralel mode (one goroutine per echo). Echolist: list with echoarea names. If list is empty, function will try to get list via list.txt request. limit: see Fetcher function. Describe fetching mode/limit.
func (*Node) Fetcher ¶
Fetcher internal goroutine. DB: db to write Echo: echo to fetch wait: sync for Fetch master to detect finishing of work cond: used for wake-up new goroutines Can work in different modes. If limit > 0, just fetch last [limit] messages (-limit:limit slice) if limit < 0, use adaptive mode, probe (-(2*n)* limit:1) messages untill find old message. if node does not support u/e slices, than full sync performed if node connection is not in Force mode, do not perform sync if not needed
func (*Node) List ¶
Return list.txt in []string if node supports it. WARNING: Only echo names are returned! Each string is just echoarea. Used for fetch all mode.
func (*Node) Post ¶
Send point message to node using POST method of /u/point scheme. pauth: secret string. msg - raw message in plaintext returns error
type Query ¶
type Query struct { Echo string Repto string From string To string Start int Lim int Blacklisted bool User User Match func(mi *MsgInfo, q Query) bool }
Query used to make queries to Index If some field of: Echo, Repto, From, To is not "" fields will be matched with MsgInfo entry (logical AND). If Match function is not nil, this function will be used for matching. Blacklisted: search in blacklisted messages if true. User: authorized access to private areas. Start & Lim: slice of query. For example: -1, 1 -- get last message in db. 0, 1 -- first.
type Tags ¶
II-tags, encoded in raw message as key1/value1/key2/value2.. string When message is decoded into Msg, key/value properties of tags associated with it. When encoding Msg, all properties will translated to tags string List - is the names of properties Hash - is the map of properties (Name->Value)
func MakeTags ¶
Creates Tags from string in key1/value1/key2/value2/... format Can return error (with unfilled Tags) if format is wrong.
func NewTags ¶
Create Tags from string in key1/value1/key2/value2/... format ignoring errors. This is useful for creating new "ii/ok" tag.
type UDB ¶
type UDB struct { Path string Names map[string]User ById map[int32]string Secrets map[string]string List []string Sync sync.RWMutex FileSize int64 }
User database. FileSize - size of points.txt to detect DB changes. Names: holds User structure by user name ById: holds user name by user id Secrets: holds user name by user secret (pauth) List: holds user names as list
func (*UDB) Add ¶
Add (register) user in database Mail is optional but someday it will be used in registration process
func (*UDB) Edit ¶
Change (replace) information about user. Gets pointer to User object and write it in DB, replacing old information. Works atomically using rename.
func (*UDB) LoadUsers ¶
Load user information in memory if it is needed (FileSize changed). So, it is safe to call it on every request.
func (*UDB) UserInfoName ¶
Return User pointer for given user name