models

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurentLimiter

type ConcurentLimiter struct {
	Locker sync.Mutex
	Num    int
}

func NewConcurentLimiter

func NewConcurentLimiter(n int) *ConcurentLimiter

func (*ConcurentLimiter) Exit

func (c *ConcurentLimiter) Exit()

func (*ConcurentLimiter) TryEnter

func (c *ConcurentLimiter) TryEnter() bool

type DownloadTask

type DownloadTask struct {
	FileName     string
	Total        int
	SuccessCount int
	WaitForDeal  *gu.IntSet
	Pieces       []*PieceInfo
}

type ErrResponse

type ErrResponse struct {
	Code string `json:"code"`
	Msg  string `json:"msg"`
}

type LocalInfo

type LocalInfo struct {
	PieceInfo

	FilePath string
}

type Node

type Node string

type NodeInfoMapper

type NodeInfoMapper struct {
	// nodeId -> addr
	Inner  map[Node]string `json:"inner"`
	Locker sync.RWMutex    `json:"-"`
}

func NewNodeInfoMapper

func NewNodeInfoMapper() *NodeInfoMapper

func (*NodeInfoMapper) Add

func (m *NodeInfoMapper) Add(node Node, addr string)

func (*NodeInfoMapper) Clone

func (m *NodeInfoMapper) Clone() *NodeInfoMapper

func (*NodeInfoMapper) Get

func (m *NodeInfoMapper) Get(node Node) string

type NodeListResp

type NodeListResp struct {
	Nodes []string `json:"nodes"`
}

type NodeSet

type NodeSet *gu.StringSet

type Piece

type Piece string

Piece is SHA1 of file-piece

type PieceInfo

type PieceInfo struct {
	Index    int    `json:"index"`
	Length   int    `json:"length"`
	Checksum string `json:"checksum"`
}

type PieceLocalMapper

type PieceLocalMapper struct {
	Inner  map[Piece]*LocalInfo `json:"inner"`
	Locker sync.RWMutex         `json:"-"`
}

func NewPieceLocalMapper

func NewPieceLocalMapper() *PieceLocalMapper

func (*PieceLocalMapper) Add

func (m *PieceLocalMapper) Add(piece Piece, info *LocalInfo)

func (*PieceLocalMapper) Clone

func (m *PieceLocalMapper) Clone() *PieceLocalMapper

deepcopy

func (*PieceLocalMapper) Get

func (m *PieceLocalMapper) Get(piece Piece) (info *LocalInfo, ok bool)

type PieceMapper

type PieceMapper struct {
	PN     map[Piece]NodeSet `json:"pn"`
	NP     map[Node]PieceSet `json:"np"`
	Locker sync.RWMutex      `json:"-"`
}

func NewPieceMapper

func NewPieceMapper() *PieceMapper

func (*PieceMapper) AddPiece

func (m *PieceMapper) AddPiece(node Node, piece Piece)

func (*PieceMapper) Clone

func (m *PieceMapper) Clone() *PieceMapper

func (*PieceMapper) GetNodeList

func (m *PieceMapper) GetNodeList(piece Piece, n int) []Node

func (*PieceMapper) PurgeNode

func (m *PieceMapper) PurgeNode(node Node)

type PieceSet

type PieceSet *gu.StringSet

type ReportParam

type ReportParam struct {
	PieceID  string  `form:"pieceID" json:"pieceID" binding:"required"`
	NodeID   string  `form:"nodeID" json:"nodeID" binding:"required"`
	Progress float64 `form:"progress" json:"progress" binding:"required"`
	File     string  `form:"file" json:"file" binding:"required"`
}

type SeedInfo

type SeedInfo struct {
	FileName    string `json:"fileName"`
	TrackerAddr string `json:"trackerAddr"`
	// total length
	Length    int          `json:"length"`
	Pieces    []*PieceInfo `json:"pieces"`
	CreatedAt time.Time    `json:"createdAt"`
}

type Session

type Session struct {
	Map    map[Node]time.Time `json:"map"`
	Locker sync.Mutex         `json:"-"`
}

func NewSession

func NewSession() *Session

func (*Session) Clone

func (s *Session) Clone() *Session

func (*Session) FindAndPurgeInvalid

func (s *Session) FindAndPurgeInvalid(expire time.Duration) []Node

func (*Session) HeartBeat

func (s *Session) HeartBeat(node Node)

Jump to

Keyboard shortcuts

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