Documentation
¶
Index ¶
- Constants
- Variables
- func AddCooldownTime(uid ptttype.UID, minutes int) (err error)
- func AddPosttimes(uid ptttype.UID, times int) (err error)
- func AddToUHash(uidInCache ptttype.UIDInStore, userID *ptttype.UserID_t) error
- func AddbrdTouchCache() (bid ptttype.Bid, err error)
- func AttachCheckSHM() (err error)
- func AttachSHM() error
- func CleanStat()
- func CloseSHM() error
- func CooldownTimeOf(uid ptttype.UID) (cooldowntime types.Time4)
- func DeUMoney(uid ptttype.UID, money int32) (int32, error)
- func DoSearchUserRaw(userID *ptttype.UserID_t, rightID *ptttype.UserID_t) (ptttype.UID, error)
- func FindBoardAutoCompleteStartIdx(keyword []byte, isAsc bool) (startIdx ptttype.SortIdx, err error)
- func FindBoardIdxByClass(cls []byte, boardID *ptttype.BoardID_t, isAsc bool) (idx ptttype.SortIdx, err error)
- func FindBoardIdxByName(boardID *ptttype.BoardID_t, isAsc bool) (idx ptttype.SortIdx, err error)
- func GetBCache(bid ptttype.Bid) (board *ptttype.BoardHeaderRaw, err error)
- func GetBTotal(bid ptttype.Bid) (total int32)
- func GetBTotalWithRetry(bid ptttype.Bid) (total int32, err error)
- func GetBid(boardID *ptttype.BoardID_t) (bid ptttype.Bid, err error)
- func GetBottomTotal(bid ptttype.Bid) (total int32)
- func GetLastPosttime(bid ptttype.Bid) (lastposttime types.Time4, err error)
- func GetUTMPNumber() (total int32)
- func GetUserID(uid ptttype.UID) (*ptttype.UserID_t, error)
- func HbflReload(bidInCache ptttype.BidInStore)
- func InitFillUHash(isOnfly bool)
- func IsHiddenBoardFriend(bidInCache ptttype.BidInStore, uidInCache ptttype.UIDInStore) bool
- func LoadUHash() (err error)
- func MoneyOf(uid ptttype.UID) (money int32)
- func NHots() (nhots uint8)
- func NewSHM(key types.Key_t, isUseHugeTlb bool, isCreate bool) error
- func NumBoards() int32
- func ParseBMList(bms *ptttype.BM_t) (uids *[ptttype.MAX_BMs]ptttype.UID)
- func PosttimesOf(uid ptttype.UID) (posttimes types.Time4)
- func ReadStat(stats ptttype.Stat) (uint32, error)
- func ReloadBCache()
- func RemoveFromUHash(uidInCache ptttype.UIDInStore) error
- func ResetBoard(bid ptttype.Bid) (err error)
- func ResolveBoardGroup(gid ptttype.Bid, bsortBy ptttype.BSortBy) (err error)
- func SanitizeBMs(bms *ptttype.BM_t) (parsedBMs *ptttype.BM_t)
- func SearchUListPID(pid types.Pid_t) (utmpID ptttype.UtmpID, uInfo *ptttype.UserInfoRaw)
- func SearchUListUserID(userID *ptttype.UserID_t) (utmpID ptttype.UtmpID, uInfo *ptttype.UserInfoRaw)
- func SearchUserRaw(userID *ptttype.UserID_t, rightID *ptttype.UserID_t) (uid ptttype.UID, err error)
- func SetBTotal(bid ptttype.Bid) (err error)
- func SetBoardChildCount(bid ptttype.Bid, count int32) (err error)
- func SetBottomTotal(bid ptttype.Bid) error
- func SetCooldownTime(uid ptttype.UID, cooldownTime types.Time4) (err error)
- func SetIsTest()
- func SetLastPosttime(bid ptttype.Bid, nowTS types.Time4) (err error)
- func SetUMoney(uid ptttype.UID, money int32) (int32, error)
- func SetUserID(uid ptttype.UID, userID *ptttype.UserID_t) (err error)
- func SetUtmpMode(uid ptttype.UID, mode ptttype.UserOpMode) (err error)
- func SortBCache()
- func StatInc(stats ptttype.Stat) error
- func TouchBPostNum(bid ptttype.Bid, delta int32) (err error)
- func UnsetIsTest()
- type SHM
- type SHMRaw
Constants ¶
const ( // from https://github.com/ptt/pttbbs/blob/master/include/pttstruct.h // commit: 6bdd36898bde207683a441cdffe2981e95de5b20 SHM_VERSION = 4842 PRE_ALLOCATED_USERS = 1000 )
const DUMMY_SHMGV2 = 512 - 6 // 6 defined int32 variables in shmGV2a
const SHM_RAW_SZ = unsafe.Sizeof(EMPTY_SHM_RAW)
Variables ¶
var ( ErrInvalidOp = errors.New("invalid op") ErrShmNotInit = errors.New("shm not init") ErrShmAlreadyInit = errors.New("shm already init") ErrShmVersion = errors.New("invalid shm version") ErrShmSize = errors.New("invalid shm size") ErrShmNotLoaded = errors.New("shm not loaded") ErrAddToUHash = errors.New("unable to add-to-uhash") ErrRemoveFromUHash = errors.New("unable to remove-from-uhash") ErrInvalidUID = errors.New("invalid uid") ErrStats = errors.New("invalid stats") ErrNotFound = errors.New("not found") ErrBusy = errors.New("busy") ErrInvalidNumBoards = errors.New("invalid num boards") )
var EMPTY_SHM_RAW = SHMRaw{}
var TestShmKey = types.Key_t(65534)
Functions ¶
func AddCooldownTime ¶ added in v0.12.0
func AddToUHash ¶
func AddToUHash(uidInCache ptttype.UIDInStore, userID *ptttype.UserID_t) error
AddToUHash
func AddbrdTouchCache ¶ added in v0.11.1
func AttachCheckSHM ¶
func AttachCheckSHM() (err error)
AttachCheckSHM
This is to have attach_check_shm (checking loaded) Should be used after LoadUHash (shmctl init) is done. Should be used only once in the beginning of the program.
func AttachSHM ¶
func AttachSHM() error
AttachSHM
This is to have attach_shm (no checking loaded), not attach_SHM (checking loaded) Should be used after LoadUHash (shmctl init) is done. Should be used only once in the beginning of the program.
func CloseSHM ¶
func CloseSHM() error
Close
XXX [WARNING] know what you are doing before using Close!. This is to be able to close the shared mem for the completeness of the mem-usage. However, in production, we create shm without the need of closing the shm.
We simply use ipcrm to delete the shm if necessary.
Currently used only in test. XXX not doing close shm to prevent opening too many shms in tests.
func CooldownTimeOf ¶ added in v0.12.0
CooldownTimeOf https://github.com/ptt/pttbbs/blob/master/include/cmbbs.h#L97
func DeUMoney ¶
DeUMoney
Add money to uid. (money can be >= 0 or < 0) Get current money and set the money by adding to current-money.
func DoSearchUserRaw ¶
func FindBoardAutoCompleteStartIdx ¶ added in v0.10.0
func FindBoardIdxByClass ¶ added in v0.10.0
func FindBoardIdxByName ¶ added in v0.10.0
func GetBTotalWithRetry ¶ added in v0.10.0
func GetBottomTotal ¶ added in v0.15.0
func GetLastPosttime ¶ added in v0.12.0
func GetUTMPNumber ¶ added in v0.19.2
func GetUTMPNumber() (total int32)
func HbflReload ¶
func HbflReload(bidInCache ptttype.BidInStore)
func InitFillUHash ¶
func InitFillUHash(isOnfly bool)
func IsHiddenBoardFriend ¶
func IsHiddenBoardFriend(bidInCache ptttype.BidInStore, uidInCache ptttype.UIDInStore) bool
func NumBoards ¶
func NumBoards() int32
NumBoards
https://github.com/ptt/pttbbs/blob/master/common/bbs/cache.c#L512
func ParseBMList ¶ added in v0.11.1
func PosttimesOf ¶ added in v0.12.0
PosttimesOf https://github.com/ptt/pttbbs/blob/master/include/cmbbs.h#L98
func ReloadBCache ¶
func ReloadBCache()
Reload BCache
https://github.com/ptt/pttbbs/blob/master/common/bbs/cache.c#L458
func ResetBoard ¶ added in v0.11.1
func ResolveBoardGroup ¶ added in v0.17.0
func SearchUListPID ¶ added in v0.5.0
func SearchUListUserID ¶
func SearchUserRaw ¶
func SearchUserRaw(userID *ptttype.UserID_t, rightID *ptttype.UserID_t) (uid ptttype.UID, err error)
SearchUser Params
userID: querying user-id. isReturn: is return the user-id in the shm.
Return
uid: err:
func SetBTotal ¶ added in v0.3.0
SetBTotal
It's possible that we loaded nothing from ReloadBCache in the beginning of the program, and then there are some articles after a while. We need to sync the btotal and lastposttime back to shm.
func SetBoardChildCount ¶ added in v0.17.0
func SetBottomTotal ¶ added in v0.3.0
func SetCooldownTime ¶ added in v0.12.0
func SetLastPosttime ¶ added in v0.12.0
func SetUtmpMode ¶ added in v0.12.0
func SetUtmpMode(uid ptttype.UID, mode ptttype.UserOpMode) (err error)
SetUtmpMode
XXX skip utmp for now.
func UnsetIsTest ¶
func UnsetIsTest()
Types ¶
type SHM ¶
type SHM struct { Shmid int IsNew bool Shmaddr unsafe.Pointer Raw SHMRaw // dummy variable to get the offset and size of the shm-fields. Shm *SHMRaw }
var Shm *SHM
//////// !!! We should have only 1 Shm.
func (*SHM) CheckMaxUser ¶ added in v0.5.0
func (s *SHM) CheckMaxUser()
func (*SHM) Close ¶
Close
XXX [WARNING] know what you are doing before using Close!. This is to be able to close the shared mem for the completeness of the mem-usage. However, in production, we create shm without the need of closing the shm.
We simply use ipcrm to delete the shm if necessary.
Currently used only in test. XXX not doing close shm to prevent opening too many shms in tests.
func (*SHM) GetBNumber ¶
func (*SHM) QsortCmpBoardClass ¶
func (s *SHM) QsortCmpBoardClass()
func (*SHM) QsortCmpBoardName ¶
func (s *SHM) QsortCmpBoardName()
type SHMRaw ¶
type SHMRaw struct { Version int32 // SHM_VERSION for verification Size int32 // sizeof(SHM_t) for verification /* uhash */ /* uhash is a userid->uid hash table -- jochang */ Userid [ptttype.MAX_USERS]ptttype.UserID_t Gap1 ptttype.UserID_t NextInHash [ptttype.MAX_USERS]ptttype.UIDInStore Gap2 [types.INT32_SZ]byte Money [ptttype.MAX_USERS]int32 Gap3 [types.INT32_SZ]byte // XXX CooldownTime is affected with USE_COOLDOWN // Require to discuss with admins about current settings. CooldownTime [ptttype.MAX_USERS]types.Time4 Gap4 [types.INT32_SZ]byte HashHead [1 << ptttype.HASH_BITS]ptttype.UIDInStore Gap5 [types.INT32_SZ]byte Number int32 /* # of users total */ Loaded int32 /* .PASSWD has been loaded? */ /* utmpshm */ // XXX UserInfoRaw is affected with NOKILLWATERBALL // Require to discuss with admins about current settings. UInfo [ptttype.USHM_SIZE]ptttype.UserInfoRaw Gap6 [ptttype.USER_INFO_RAW_SZ]byte Sorted [2][ptttype.SORT_BY_MAX][ptttype.USHM_SIZE]ptttype.UtmpID /* 第一維double buffer 由currsorted指向目前使用的 第二維sort type */ Gap7 [types.INT32_SZ]byte CurrSorted int32 UTMPUptime types.Time4 UTMPNumber int32 UTMPNeedSort byte UTMPBusyState byte /* brdshm */ Gap8 [types.INT32_SZ]byte BMCache [ptttype.MAX_BOARD][ptttype.MAX_BMs]ptttype.UID Gap9 [types.INT32_SZ]byte BCache [ptttype.MAX_BOARD]ptttype.BoardHeaderRaw Gap10 [types.INT32_SZ]byte BSorted [ptttype.BSORT_BY_MAX][ptttype.MAX_BOARD]ptttype.BidInStore /* 0: by name 1: by class */ /* 裡頭存的是 bid-1 */ Gap11 [types.INT32_SZ]byte // XXX NHOTs and HBcache are affected with HOTBOARDCACHE // Require to discuss with admins about current settings. NHOTs uint8 HBcache [ptttype.HOTBOARDCACHE]ptttype.BidInStore Gap12 [types.INT32_SZ]byte BusyStateB [ptttype.MAX_BOARD]types.Time4 Gap13 [types.INT32_SZ]byte Total [ptttype.MAX_BOARD]int32 /* numbre of all posts */ Gap14 [types.INT32_SZ]byte NBottom [ptttype.MAX_BOARD]uint8 /* number of bottom */ Gap15 [types.INT32_SZ]byte Hbfl [ptttype.MAX_BOARD][ptttype.MAX_FRIEND + 1]ptttype.UID /* hidden board friend list, 0: load time, 1-MAX_FRIEND: uid (板友們) (0th: load 的時間. 其他欄位: 用來記錄板友的 uid) (XXX 在之後 Time8 時需要改變 structure) */ Gap16 [types.INT32_SZ]byte LastPostTime [ptttype.MAX_BOARD]types.Time4 Gap17 [types.INT32_SZ]byte BUptime types.Time4 BTouchTime types.Time4 BNumber int32 BBusyState int32 CloseVoteTime types.Time4 /* pttcache */ Notes [ptttype.MAX_ADBANNER][256 * ptttype.MAX_ADBANNER_HEIGHT]byte Gap18 [types.INT32_SZ]byte TodayIs [ptttype.TODAYISSZ]byte // FIXME remove it NeverUsedNNotes_ [ptttype.MAX_ADBANNER_SECTION]int32 /* 一節中有幾個 看板 */ Gap19 [types.INT32_SZ]byte // FIXME remove it NeverUsedNextRefresh_ [ptttype.MAX_ADBANNER_SECTION]int32 /* 下一次要refresh的 看板 */ Gap20 [types.INT32_SZ]byte LoginMsg ptttype.MsgQueueRaw /* 進站水球 */ LastFilm int32 LastUsong int32 PUptime types.Time4 PTouchTime types.Time4 PBusyState int32 /* SHM 中的全域變數, 可用 shmctl 設定或顯示. 供動態調整或測試使用 */ GV2 shmGV2 /* statistic */ Statistic [ptttype.STAT_MAX]uint32 // 從前作為故鄉使用 (fromcache). 現已被 daemon/fromd 取代。 DeprecatedHomeIp_ [ptttype.MAX_FROM]uint32 DeprecatedHomeMask_ [ptttype.MAX_FROM]uint32 DeprecatedHomeDesc_ [ptttype.MAX_FROM][32]byte DeprecatedHomeNum_ int32 MaxUser int32 MaxTime types.Time4 FUptime types.Time4 FTouchTime types.Time4 FBusyState int32 }