tickets

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATE_NEW int32 = iota
	STATE_ACK
	STATE_CANCEL
	STATE_TIMEOUT
)
View Source
const (
	ACK_ACCEPT int32 = iota
	ACK_CANCEL
)
View Source
const (
	STORE_SEND int32 = iota
	STORE_RECV
)

Variables

View Source
var SendingListTypeError = fmt.Errorf("Elements in prapareSendingList is not TicketAck")

Functions

func NewLinkedTicketStore

func NewLinkedTicketStore() *linkedTicketStore

Types

type BasicTicket

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

func CreateBasicTicket

func CreateBasicTicket(sendTo peer.ID, contentId cid.Cid, blockSize int64) *BasicTicket

func CreateBasicTicketWithTime

func CreateBasicTicketWithTime(sendTo peer.ID, contentId cid.Cid, blockSize int64, timeStamp int64) *BasicTicket

func NewBasicTicket

func NewBasicTicket(ticket *pb.Ticket) (*BasicTicket, error)

func (*BasicTicket) ACKed

func (t *BasicTicket) ACKed()

func (*BasicTicket) BasicInfo

func (t *BasicTicket) BasicInfo() string

func (*BasicTicket) Canceled

func (t *BasicTicket) Canceled()

func (*BasicTicket) Cid

func (t *BasicTicket) Cid() cid.Cid

func (*BasicTicket) GetSize

func (t *BasicTicket) GetSize() int64

func (*BasicTicket) GetState

func (t *BasicTicket) GetState() int32

func (*BasicTicket) GetStateString

func (t *BasicTicket) GetStateString() string

func (*BasicTicket) Level

func (t *BasicTicket) Level() int64

func (*BasicTicket) Loggable

func (t *BasicTicket) Loggable() map[string]interface{}

func (*BasicTicket) Publisher

func (t *BasicTicket) Publisher() peer.ID

func (*BasicTicket) SendTo

func (t *BasicTicket) SendTo() peer.ID

func (*BasicTicket) SetPublisher

func (t *BasicTicket) SetPublisher(p peer.ID)

func (*BasicTicket) SetTimeStamp

func (a *BasicTicket) SetTimeStamp(timeStamp int64)

func (*BasicTicket) ToProto

func (t *BasicTicket) ToProto() *pb.Ticket

type BasicTicketAck

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

func CreateBasicTicketAck

func CreateBasicTicketAck(publisher peer.ID, receiver peer.ID, contentId cid.Cid, acktype int32) *BasicTicketAck

func NewBasicTicketAck

func NewBasicTicketAck(ack *pb.TicketAck) (*BasicTicketAck, error)

func (*BasicTicketAck) ACK

func (a *BasicTicketAck) ACK() int32

func (*BasicTicketAck) Cid

func (a *BasicTicketAck) Cid() cid.Cid

func (*BasicTicketAck) Loggable

func (a *BasicTicketAck) Loggable() map[string]interface{}

func (*BasicTicketAck) Publisher

func (a *BasicTicketAck) Publisher() peer.ID

func (*BasicTicketAck) Receiver

func (a *BasicTicketAck) Receiver() peer.ID

func (*BasicTicketAck) ToProto

func (a *BasicTicketAck) ToProto() *pb.TicketAck

type InvalidPublisherError

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

func (*InvalidPublisherError) Error

func (e *InvalidPublisherError) Error() string

type Loggable

type Loggable interface {
	Loggable() map[string]interface{}
}

type NotInitializeError

type NotInitializeError struct{}

func (*NotInitializeError) Error

func (e *NotInitializeError) Error() string

type Ticket

type Ticket interface {
	Publisher() peer.ID // Needed because the ticket receiver should send ack to ticket sender
	SendTo() peer.ID
	Cid() cid.Cid
	Level() int64 // Higher level, lower priority
	//Valid(peer.ID, peer.ID) bool
	GetSize() int64
	GetState() int32
	BasicInfo() string
	//Called when receive ack for this Ticket
	ACKed()
	//Called when receive cancel for thie Ticket
	Canceled()
	//TODO: Add digital signature to ticket. - Riften
	//Signature String
	ToProto() *pb.Ticket

	SetPublisher(peer.ID)
	SetTimeStamp(timeStamp int64)

	Loggable
}

type TicketAck

type TicketAck interface {
	// Publisher, Receiver, Cid should return the same value as Ticket
	// They identify the ack for specific ticket
	Publisher() peer.ID
	Receiver() peer.ID
	Cid() cid.Cid

	// Type of ack
	ACK() int32
	ToProto() *pb.TicketAck

	//Loggable() map[string]interface{}
	Loggable
}

func AckFromTicket

func AckFromTicket(p peer.ID, t Ticket, ackType int32) TicketAck

func GetAcceptAcks

func GetAcceptAcks(p peer.ID, ts []Ticket) []TicketAck

func GetRejectAcks

func GetRejectAcks(p peer.ID, ts []Ticket) []TicketAck

type TicketNotFound

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

func (*TicketNotFound) Error

func (e *TicketNotFound) Error() string

type TicketStore

type TicketStore interface {
	AddTicket(ticket Ticket) error // called after sending a ticket
	AddTickets(ticket []Ticket) error
	GetTickets(cid cid.Cid) ([]Ticket, error)
	//GetTicketsByCids(cids []cid.Cid) (map[cid.Cid] []Ticket, error)
	RemoveTicket(pid peer.ID, cid cid.Cid) error // remove a specific ticket from the `sended ticket list`, called after receive a reject
	RemoveTicketEqualsTo(ticket Ticket)
	Clean()
	RemoveCanceled() int

	PopTickets() *TicketTask

	TicketNumber() int
	TicketSize() int64

	// Interfaces for sending tickets - Add by Jerry
	RemoveTickets(pid peer.ID, cids []cid.Cid) error     // remove a set of tickets from the `sended ticket list`
	PrepareSending(acks []TicketAck) error               // called if don't have corresponding block when receiving an ACK, put the entry on a list
	RemoveSendingTask(pid peer.ID, cids []cid.Cid) error // remove a specific task from the `prepared sending task list`, called after receive a reject
	PopSendingTasks(cids []cid.Cid) ([]TicketAck, error) // pop all tasks for a specific cid in `prepared sending task list`, called when a block is received
	PredictTime() int64                                  // Get the predicted time used to complete all the tickets sent. Return time in millsecond

	// Interfaces for receving tickets - Add by Jerry
	StoreReceivedTickets(tickets []Ticket) error
	GetReceivedTicket(cids []cid.Cid) (map[cid.Cid]Ticket, error)
}

*

  • ticketStore is used to store the tickets published.
  • Please do not use it to store the ticket received!!!
  • It is used in following cases:
  • - Compute the size of tickets waiting for deliving
  • - Record the tickets so that we can verify the ticket ack.
  • - Control how many tickets to publish

type TicketTask

type TicketTask struct {
	Target  peer.ID
	Tickets []Ticket
}

Jump to

Keyboard shortcuts

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