Documentation
¶
Index ¶
- Constants
- Variables
- func MakeCID(data []byte) (cid.Cid, error)
- func MakeHaveMsg() []byte
- func MakeKey(key string) string
- func MakeNopeMsg() []byte
- func MakeSendMsg(repoName string, hash []byte) []byte
- func MakeWantMsg(repoName string, hash []byte) []byte
- func ParseObjectKeyToHex(key []byte) (string, error)
- func ParseWantOrSendMsg(msg []byte) (typ string, repoName string, hash []byte, err error)
- func ReadWantOrSendMsg(r io.Reader) (typ string, repoName string, hash []byte, err error)
- type Announcer
- type AnnouncerService
- type CheckFunc
- type DHT
- type GetAncestorArgs
- type ProviderInfo
- type ProviderTracker
- type Session
- type Streamer
Constants ¶
View Source
const ( MsgTypeWant = "WANT" MsgTypeHave = "HAVE" MsgTypeSend = "SEND" MsgTypeNope = "NOPE" MsgTypePack = "PACK" )
View Source
const (
ObjectNamespace = "obj"
)
Variables ¶
View Source
var ( ErrObjNotFound = fmt.Errorf("object not found") MsgTypeLen = 4 )
Functions ¶
func MakeSendMsg ¶
MakeSendMsg creates a 'SEND' message
- Format: SEND <reponame> <20 bytes hash>
- <reponame>: Length varies but not more than MaxResourceNameLength
func MakeWantMsg ¶
MakeWantMsg creates a 'WANT' message.
- Format: WANT <reponame> <20 bytes hash>
- <reponame>: Length varies but not more than MaxResourceNameLength
func ParseObjectKeyToHex ¶
ParseObjectKeyToHex parses an object key to an hex-encoded version
func ParseWantOrSendMsg ¶
ParseWantOrSendMsg parses a 'WANT/SEND' message
Types ¶
type Announcer ¶
type Announcer interface { // Announce queues an object to be announced. // objType is the type of the object. // key is the unique identifier of the object. // doneCB is called after successful announcement // Returns true if object has been successfully queued Announce(objType int, repo string, key []byte, doneCB func(error)) bool // Start starts the announcer. // Panics if reference announcer is already started. Start() // IsRunning checks if the announcer is running. IsRunning() bool // HasTask checks whether there are one or more unprocessed tasks. HasTask() bool // NewSession creates an instance of Session NewSession() Session // Stop stops the announcer and releases resources Stop() // RegisterChecker allows external caller to register existence checker // for a given object type. Only one checker per object type. RegisterChecker(objType int, checker CheckFunc) }
type AnnouncerService ¶
type AnnouncerService interface { // Announce queues an object to be announced. // objType is the type of the object. // key is the unique identifier of the object. // doneCB is called after successful announcement Announce(objType int, repo string, key []byte, doneCB func(error)) bool }
AnnouncerService is like Announcer but exposes limited methods
type DHT ¶
type DHT interface { // Store adds a value corresponding to the given key Store(ctx context.Context, key string, value []byte) error // Lookup searches for a value corresponding to the given key Lookup(ctx context.Context, key string) ([]byte, error) // GetProviders finds peers capable of providing value for the given key GetProviders(ctx context.Context, key []byte) ([]peer.AddrInfo, error) // Announce informs the network that it can provide value for the given key Announce(objType int, repo string, key []byte, doneCB func(error)) bool // NewAnnouncerSession creates an announcer session NewAnnouncerSession() Session // RegisterChecker registers an object checker to the announcer. RegisterChecker(objType int, f CheckFunc) // ObjectStreamer returns the object streamer ObjectStreamer() Streamer // Host returns the wrapped IPFS host Host() host.Host // DHT returns the wrapped IPFS dht DHT() *kaddht.IpfsDHT // Start starts the DHT Start() error // Peers returns a list of all peers Peers() (peers []string) // Stop closes the host Stop() error }
DHT represents a distributed hash table
type GetAncestorArgs ¶
type GetAncestorArgs struct { // RepoName is the target repository to query commits from. RepoName string // StartHash is the hash of the object to start from StartHash []byte // EndHash is the hash of the object that indicates the end of the query. // If provided, it must exist on the local repository of the caller. EndHash []byte // ExcludeEndCommit when true, indicates that the end commit should not be fetched. ExcludeEndCommit bool // GitBinPath is the path to the git binary GitBinPath string // ReposDir is the root directory containing all repositories ReposDir string // ResultCB is a callback used for collecting packfiles as they are fetched. // If not set, all packfile results a collected and return at the end of the query. // hash is the object hash of the object that owns the packfile. ResultCB func(packfile io.ReadSeekerCloser, hash string) error }
GetAncestorArgs contain arguments for GetAncestors method
type ProviderInfo ¶
type ProviderInfo struct { Addr *peer.AddrInfo Failed int LastFailure time.Time LastSeen time.Time }
ProviderInfo contains information about a provider
type ProviderTracker ¶
type ProviderTracker interface { // Register registers a new provider so it can be tracked Register(addrs ...peer.AddrInfo) // NumProviders returns the number of registered providers. NumProviders() int // Get a provider's information. If cb is provided, it is called with the provider Get(id peer.ID, cb func(*ProviderInfo)) *ProviderInfo // IsGood checks whether the given peer has a good record. IsGood(id peer.ID) bool // Ban bans a provider for the given duration. // If a peer is currently banned, the duration is added to its current ban time. Ban(peer peer.ID, dur time.Duration) // MarkFailure increments a provider's failure count. // When failure count reaches a max, ban the provider. MarkFailure(id peer.ID) // MarkSeen marks the provider's last seen time and resets its failure count. MarkSeen(id peer.ID) // PeerSentNope registers a NOPE response from the given peer indicating that // the object represented by the given key is unknown to it. PeerSentNope(id peer.ID, key []byte) // DidPeerSendNope checks whether the given peer previously sent NOPE for a key DidPeerSendNope(id peer.ID, key []byte) bool }
ProviderTracker describes a structure for tracking provider performance
type Streamer ¶
type Streamer interface { GetCommit(ctx context.Context, repo string, hash []byte) (packfile io.ReadSeekerCloser, commit *object.Commit, err error) GetCommitWithAncestors(ctx context.Context, args GetAncestorArgs) (packfiles []io.ReadSeekerCloser, err error) GetTaggedCommitWithAncestors(ctx context.Context, args GetAncestorArgs) (packfiles []io.ReadSeekerCloser, err error) GetTag(ctx context.Context, repo string, hash []byte) (packfile io.ReadSeekerCloser, tag *object.Tag, err error) OnRequest(s network.Stream) (success bool, err error) GetProviders(ctx context.Context, repoName string, objectHash []byte) ([]peer.AddrInfo, error) }
Streamer provides an interface for providing objects and fetching various object types from the underlying DHT network.
Click to show internal directories.
Click to hide internal directories.