core

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandBytes

func RandBytes(n int) []byte

Types

type Announcement

type Announcement struct {
	Raw         map[string]interface{}
	From        net.UDPAddr
	Peer        net.Addr
	InfoHash    []byte
	InfoHashHex string
}

type Announcements

type Announcements struct {
	Mu    sync.RWMutex
	Ll    *list.List
	Limit int
	Input chan struct{}
}

func (*Announcements) Full

func (a *Announcements) Full() bool

func (*Announcements) Get

func (a *Announcements) Get() *Announcement

func (*Announcements) Len

func (a *Announcements) Len() int

func (*Announcements) Put

func (a *Announcements) Put(ac *Announcement)

func (*Announcements) Wait

func (a *Announcements) Wait() <-chan struct{}

type BlackList

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

func NewBlackList

func NewBlackList(expiredAfter time.Duration, limit int) *BlackList

func (*BlackList) Add

func (b *BlackList) Add(addr string)

func (*BlackList) Has

func (b *BlackList) Has(addr string) bool

type Dht

type Dht struct {
	Mu             sync.Mutex
	Announcements  *Announcements
	ChNode         chan *Node
	Die            chan struct{}
	ErrDie         error
	LocalID        nodeID
	Conn           *net.UDPConn
	QueryTypes     map[string]func(map[string]interface{}, net.UDPAddr)
	FriendsLimiter *rate.Limiter
	Secret         []byte
	Seeds          []string
}

func NewDHT

func NewDHT(laddr string, maxFriendsPerSec int) (*Dht, error)

func (*Dht) FindNode

func (d *Dht) FindNode(to string, target nodeID)

func (*Dht) Join

func (d *Dht) Join()

func (*Dht) Listen

func (d *Dht) Listen()

func (*Dht) MakeFriends

func (d *Dht) MakeFriends()

func (*Dht) Run

func (d *Dht) Run()

func (*Dht) Send

func (d *Dht) Send(dict map[string]interface{}, to net.UDPAddr) error

func (*Dht) Summarize

func (d *Dht) Summarize(dict map[string]interface{}, from net.UDPAddr) *Announcement

type MetaWire

type MetaWire struct {
	InfoHash     string
	From         string
	PeerID       string
	Conn         *net.TCPConn
	Timeout      time.Duration
	MetaDataSize int
	UtMetadata   int
	NumOfPieces  int
	Pieces       [][]byte
	Err          error
}

func NewMetaWire

func NewMetaWire(infohash string, from string, timeout time.Duration) *MetaWire

func (*MetaWire) Fetch

func (mw *MetaWire) Fetch() ([]byte, error)

func (*MetaWire) FetchCtx

func (mw *MetaWire) FetchCtx(ctx context.Context) ([]byte, error)

func (*MetaWire) Free

func (mw *MetaWire) Free()

func (*MetaWire) Read

func (mw *MetaWire) Read(ctx context.Context, size uint32) ([]byte, error)

func (*MetaWire) Write

func (mw *MetaWire) Write(ctx context.Context, data []byte) error

type Node

type Node struct {
	Addr string
	Id   string
}

Jump to

Keyboard shortcuts

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