thread

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2015 License: BSD-3-Clause Imports: 16 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInUpdateRange

func IsInUpdateRange(nstamp int64) bool

IsInUpdateRange returns true if stamp is in updateRange.

Types

type Cache

type Cache struct {
	*CacheConfig
	Datfile string
	// contains filtered or unexported fields
}

Cache represents cache of one file.

func NewCache

func NewCache(datfile string) *Cache

NewCache read tag files to set and returns cache obj. it uses sync.pool to ensure that only one cache obj exists for one datfile. and garbage collected when not used.

func (*Cache) AddTags

func (c *Cache) AddTags(vals []string)

AddTags add user tag list from vals.

func (*Cache) Datpath

func (c *Cache) Datpath() string

Datpath returns real file path of this cache.

func (*Cache) Exists

func (c *Cache) Exists() bool

Exists return true is datapath exists.

func (*Cache) GetCache

func (c *Cache) GetCache() bool

GetCache checks nodes in lookuptable have the cache. if found gets records.

func (*Cache) GetContents

func (c *Cache) GetContents() []string

GetContents returns recstrs of cache. len(recstrs) is <=2.

func (*Cache) GetTags

func (c *Cache) GetTags() Tagslice

GetTags returns copy of usertags.

func (*Cache) GetTagstrSlice

func (c *Cache) GetTagstrSlice() []string

GetTagstrSlice returns tagstr slice of user tag.

func (*Cache) Gettitle

func (c *Cache) Gettitle() string

Gettitle returns title part if *_*. returns ca.datfile if not.

func (*Cache) HasRecord

func (c *Cache) HasRecord() bool

HasRecord return true if cache has more than one records or removed records.

func (*Cache) HasTag

func (c *Cache) HasTag(board string) bool

HasTag returns true if cache has tagstr=board tag in usertag or sugtag.

func (*Cache) HasTagstr

func (c *Cache) HasTagstr(tagstr string) bool

HasTagstr returns true if tag has tagstr.

func (*Cache) LenTags

func (c *Cache) LenTags() int

LenTags returns # of set user tag.

func (*Cache) LoadRecords

func (c *Cache) LoadRecords() RecordMap

LoadRecords loads and returns record maps from the disk .

func (*Cache) ReadInfo

func (c *Cache) ReadInfo() *CacheInfo

ReadInfo reads cache info from disk and returns #,velocity, and total size.

func (*Cache) RecentStamp

func (c *Cache) RecentStamp() int64

RecentStamp returns time of getting by /recent.

func (*Cache) Remove

func (c *Cache) Remove()

Remove Remove all files and dirs of cache.

func (*Cache) SetTags

func (c *Cache) SetTags(vals []string)

SetTags sets user tag list from vals.

func (*Cache) SetupDirectories

func (c *Cache) SetupDirectories()

SetupDirectories make necessary dirs.

func (*Cache) SyncTag

func (c *Cache) SyncTag()

SyncTag saves usertags to files.

func (*Cache) TagString

func (c *Cache) TagString() string

TagString returns string of user tag.

type CacheConfig

type CacheConfig struct {
	CacheDir          string
	RecordLimit       int
	SyncRange         int64
	GetRange          int64
	NodeManager       *node.Manager
	UserTag           *UserTag
	SuggestedTagTable *SuggestedTagTable
	RecentList        *RecentList
	Fmutex            *sync.RWMutex
}

CacheConfig is config for Cache struct.

var (

	//CacheCfg is config for Cache struct.it must be set before using it.
	CacheCfg *CacheConfig
)

type CacheInfo

type CacheInfo struct {
	Size     int64 //size of total records
	Len      int   //# of records
	Velocity int   //# of new records in one day
	Stamp    int64 //stamp of newest record
	Oldest   int64 //oldeest stamp
}

CacheInfo represents size/len/velocity of cache.

type CacheList

type CacheList struct {
	Caches Caches
	*CacheListConfig
}

CacheList is slice of *cache

func NewCacheList

func NewCacheList() *CacheList

NewCacheList loads all Caches in disk and returns cachelist obj.

func (*CacheList) Append

func (c *CacheList) Append(cc *Cache)

Append adds cache cc to list.

func (*CacheList) CleanRecords

func (c *CacheList) CleanRecords()

CleanRecords remove old or duplicates records for each Caches.

func (*CacheList) Getall

func (c *CacheList) Getall()

Getall reload all records in cache in cachelist from network.

func (*CacheList) Len

func (c *CacheList) Len() int

Len returns # of Caches

func (*CacheList) RemoveRemoved

func (c *CacheList) RemoveRemoved()

RemoveRemoved removes files in removed dir if old.

func (*CacheList) Search

func (c *CacheList) Search(query *regexp.Regexp) Caches

Search reloads records in Caches in cachelist and returns slice of cache which matches query.

func (*CacheList) Swap

func (c *CacheList) Swap(i, j int)

Swap swaps cache order.

type CacheListConfig

type CacheListConfig struct {
	SaveSize    int
	SaveRemoved int64
	CacheDir    string
	SaveRecord  int64
	Fmutex      *sync.RWMutex
}

CacheListConfig is a config of CacheList struct.

var CacheListCfg *CacheListConfig

CacheListCfg is a config obj of CacheList struct. it must be set before using it.

type Caches

type Caches []*Cache

Caches is a slice of *cache

func (Caches) Has

func (c Caches) Has(cc *Cache) bool

Has return true is Caches has cache cc

func (Caches) Len

func (c Caches) Len() int

Len returns size of cache slice.

func (Caches) Swap

func (c Caches) Swap(i, j int)

Swap swaps order of cache slice.

type RecentList

type RecentList struct {
	*RecentListConfig
	// contains filtered or unexported fields
}

RecentList represents records list udpated by remote host and gotten by /gateway.cgi/Recent

func NewRecentList

func NewRecentList(cfg *RecentListConfig) *RecentList

NewRecentList load the saved file and create a RecentList obj.

func (*RecentList) Append

func (r *RecentList) Append(rec *Record)

Append add a infos generated from the record.

func (*RecentList) CreateAllCachedirs

func (r *RecentList) CreateAllCachedirs()

CreateAllCachedirs creates all dirs in recentlist to be retrived when called recentlist.getall. (heavymoon)

func (*RecentList) GetRecords

func (r *RecentList) GetRecords() []*RecordHead

GetRecords copies and returns recorcds in recentlist.

func (*RecentList) Getall

func (r *RecentList) Getall()

Getall retrieves Recent records from nodes in searchlist and stores them. tags are shuffled and truncated to tagsize and stored to sugtags in cache. also source nodes are stored into lookuptable. also tags which Recentlist doen't have in sugtagtable are truncated

func (*RecentList) MakeRecentCachelist

func (r *RecentList) MakeRecentCachelist() Caches

MakeRecentCachelist returns sorted cachelist copied from Recentlist. which doens't contain duplicate Caches.

func (*RecentList) Newest

func (r *RecentList) Newest(Datfile string) *RecordHead

Newest returns newest record of datfile in the list. if not found returns nil.

func (*RecentList) Sync

func (r *RecentList) Sync()

Sync remove old records and save to the file.

type RecentListConfig

type RecentListConfig struct {
	RecentRange       int64
	TagSize           int
	Recent            string
	Fmutex            *sync.RWMutex
	NodeManager       *node.Manager
	SuggestedTagTable *SuggestedTagTable
}

RecentListConfig is confi for Recentlist struct.

type Record

type Record struct {
	*RecordConfig
	RecordHead
	// contains filtered or unexported fields
}

Record represents one record.

func NewRecord

func NewRecord(datfile, idstr string) *Record

NewRecord parse idstr unixtime+"_"+md5(bodystr)), set stamp and id, and return record obj. if parse failes returns nil.

func (*Record) AttachPath

func (r *Record) AttachPath(thumbnailSize string) string

AttachPath returns attach path by creating path from args.

func (*Record) BodyString

func (r *Record) BodyString() string

BodyString retuns bodystr not including attach field, and shorten pubkey.

func (*Record) Build

func (r *Record) Build(stamp int64, body map[string]string, passwd string) string

Build sets params in record from args and return id.

func (*Record) CopyRecordHead

func (r *Record) CopyRecordHead() RecordHead

CopyRecordHead copies and returns recordhead.

func (*Record) Exists

func (r *Record) Exists() bool

Exists return true if record file exists.

func (*Record) GetBodyValue

func (r *Record) GetBodyValue(k string, def string) string

GetBodyValue returns value of key k return def if not exists.

func (*Record) GetData

func (r *Record) GetData(n *node.Node) error

GetData gets records from node n and checks its is same as stamp and id in args. save recs if success. returns errSpam or errGet.

func (*Record) Getbody

func (r *Record) Getbody() string

Getbody retuns contents of rec after loading if needed.

func (*Record) HasBodyValue

func (r *Record) HasBodyValue(k string) bool

HasBodyValue returns true if key k exists

func (*Record) IsSpam

func (r *Record) IsSpam() bool

IsSpam returns true if Recstr is listed in spam.txt

func (*Record) Load

func (r *Record) Load() error

Load loads a record file and parses it.

func (r *Record) MakeAttachLink(sakuHost string) string

MakeAttachLink makes and returns attached file link.

func (*Record) Recstr

func (r *Record) Recstr() string

Recstr returns one line in the record file.

func (*Record) Remove

func (r *Record) Remove() error

Remove moves the record file to remove path

func (*Record) Removed

func (r *Record) Removed() bool

Removed return true if record is removed (i.e. exists.in removed path)

func (*Record) ShortPubkey

func (r *Record) ShortPubkey() string

ShortPubkey returns short version of pubkey.

func (*Record) Sync

func (r *Record) Sync()

Sync saves Recstr to the file. if attached file exists, saves it to attached path. if signed, also saves body part.

type RecordConfig

type RecordConfig struct {
	DefaultThumbnailSize string
	CacheDir             string
	Fmutex               *sync.RWMutex
	CachedRule           *util.RegexpList
	RecordLimit          int
}

RecordConfig is the config for Record struct.

var (
	//RecordCfg is the config for Record struct.
	//it must be set befor using.
	RecordCfg *RecordConfig
)

type RecordHead

type RecordHead struct {
	Datfile string //cache file name
	Stamp   int64  //unixtime
	ID      string //md5(bodystr)
}

RecordHead represents one line in updatelist/recentlist

func (*RecordHead) Idstr

func (u *RecordHead) Idstr() string

Idstr returns real file name of the record file.

func (*RecordHead) Recstr

func (u *RecordHead) Recstr() string

Recstr returns one line of update/recentlist file.

type RecordMap

type RecordMap map[string]*Record

RecordMap is a map key=datfile, value=record.

func (RecordMap) Get

func (r RecordMap) Get(i string, def *Record) *Record

Get returns records which hav key=i. return def if not found.

func (RecordMap) Keys

func (r RecordMap) Keys() []string

Keys returns key strings(ids) of records

type SortByStamp

type SortByStamp struct {
	Caches
	// contains filtered or unexported fields
}

SortByStamp is for sorting by stamp.

func NewSortByStamp

func NewSortByStamp(cs Caches, recentStamp bool) *SortByStamp

NewSortByStamp makes stamps for caches and returns SortByStamp obj.

func (*SortByStamp) Less

func (c *SortByStamp) Less(i, j int) bool

Less returns true if cache[i].stamp < cache[j].stamp.

func (*SortByStamp) Swap

func (c *SortByStamp) Swap(i, j int)

Swap swaps order of cache slice.

type SortByVelocity

type SortByVelocity struct {
	Caches
	// contains filtered or unexported fields
}

SortByVelocity is for sorting by velocity.

func NewSortByVelocity

func NewSortByVelocity(cs Caches) *SortByVelocity

NewSortByVelocity makes velocity for caches and returns SortByVelocity obj.

func (*SortByVelocity) Less

func (c *SortByVelocity) Less(i, j int) bool

Less returns true if cache[i].velocity < cache[j].velocity. if velocity[i]==velocity[j], returns true if cache[i].size< cache[j].size.

func (*SortByVelocity) Swap

func (c *SortByVelocity) Swap(i, j int)

Swap swaps order of cache slice.

type SuggestedTagTable

type SuggestedTagTable struct {
	*SuggestedTagTableConfig
	// contains filtered or unexported fields
}

SuggestedTagTable represents tags associated with datfile retrieved from network.

func NewSuggestedTagTable

func NewSuggestedTagTable(cfg *SuggestedTagTableConfig) *SuggestedTagTable

NewSuggestedTagTable make SuggestedTagTable obj and read info from the file.

func (*SuggestedTagTable) Get

func (s *SuggestedTagTable) Get(datfile string, def Tagslice) Tagslice

Get returns copy of Tagslice associated with datfile or returns def if not exists.

func (*SuggestedTagTable) HasTagstr

func (s *SuggestedTagTable) HasTagstr(datfile string, tagstr string) bool

HasTagstr return true if one of tags has tagstr

func (*SuggestedTagTable) String

func (s *SuggestedTagTable) String(datfile string) string

String return tagstr string of datfile.

type SuggestedTagTableConfig

type SuggestedTagTableConfig struct {
	TagSize int
	Sugtag  string
	Fmutex  *sync.RWMutex
}

SuggestedTagTableConfig is a config for SuggestedTagTable struct.

type Tag

type Tag struct {
	Tagstr string
	// contains filtered or unexported fields
}

Tag represents one tag.

type Tagslice

type Tagslice []*Tag

Tagslice is a slice of *Tag.

func (Tagslice) GetTagstrSlice

func (t Tagslice) GetTagstrSlice() []string

GetTagstrSlice returns tagstr slice of tags.

func (Tagslice) HasTagstr

func (t Tagslice) HasTagstr(tagstr string) bool

HasTagstr return true if one of tags has tagstr

func (Tagslice) Len

func (t Tagslice) Len() int

Len returns size of tags.

func (Tagslice) Less

func (t Tagslice) Less(i, j int) bool

Less is true if weight[i]< weigt[j]

func (Tagslice) Swap

func (t Tagslice) Swap(i, j int)

Swap swaps tag order.

type UpdateQue

type UpdateQue struct {
	*UpdateQueConfig
	// contains filtered or unexported fields
}

UpdateQue is for telling updates of records. it records hash of updated records for 1 hour not to tell again.

func NewUpdateQue

func NewUpdateQue(cfg *UpdateQueConfig) *UpdateQue

NewUpdateQue makes and returns UpdateQue obj.

func (*UpdateQue) UpdateNodes

func (u *UpdateQue) UpdateNodes(rec *Record, n *node.Node)

UpdateNodes do doUpdateNode for each records using related nodes. if success to doUpdateNode, add node to updatelist and recentlist and removes the record from queue.

type UpdateQueConfig

type UpdateQueConfig struct {
	RecentList  *RecentList
	NodeManager *node.Manager
}

UpdateQueConfig is a config of UpdateQue.

type UserTag

type UserTag struct {
	*UserTagConfig
}

UserTag represents tags saved by the user.

func NewUserTag

func NewUserTag(cfg *UserTagConfig) *UserTag

NewUserTag returns UserTag obj.

func (*UserTag) Get

func (u *UserTag) Get() Tagslice

Get reads tags from the disk if dirty and returns Tagslice.

type UserTagConfig

type UserTagConfig struct {
	CacheDir string
	Fmutex   *sync.RWMutex
}

UserTagConfig is a config for UserTag.

Jump to

Keyboard shortcuts

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