Documentation ¶
Overview ¶
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func NamespaceFixture() string
- func PieceHash() hash.Hash32
- func TagFixture() string
- func ValidateSHA256(s string) error
- type BlobFixture
- type BlobInfo
- type Digest
- func (d Digest) Algo() string
- func (d Digest) Hex() string
- func (d Digest) MarshalJSON() ([]byte, error)
- func (d *Digest) Scan(src interface{}) error
- func (d Digest) ShardID() string
- func (d Digest) String() string
- func (d *Digest) UnmarshalJSON(str []byte) error
- func (d Digest) Value() (driver.Value, error)
- type DigestList
- type Digester
- type InfoHash
- type MetaInfo
- func (mi *MetaInfo) Digest() Digest
- func (mi *MetaInfo) GetPieceLength(i int) int64
- func (mi *MetaInfo) GetPieceSum(i int) uint32
- func (mi *MetaInfo) InfoHash() InfoHash
- func (mi *MetaInfo) Length() int64
- func (mi *MetaInfo) NumPieces() int
- func (mi *MetaInfo) PieceLength() int64
- func (mi *MetaInfo) Serialize() ([]byte, error)
- type PeerContext
- type PeerID
- type PeerIDFactory
- type PeerInfo
- type PeerInfos
- type PeersByPeerID
Constants ¶
const (
// DigestEmptyTar is the sha256 digest of an empty tar file.
DigestEmptyTar = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
)
const (
// SHA256 is the only algorithm supported.
SHA256 = "sha256"
)
Variables ¶
var ErrInvalidPeerIDLength = errors.New("peer id has invalid length")
ErrInvalidPeerIDLength returns when a string peer id does not decode into 20 bytes.
Functions ¶
func ValidateSHA256 ¶
ValidateSHA256 returns error if s is not a valid SHA256 hex digest.
Types ¶
type BlobFixture ¶
BlobFixture joins all information associated with a blob for testing convenience.
func CustomBlobFixture ¶
func CustomBlobFixture(content []byte, digest Digest, mi *MetaInfo) *BlobFixture
CustomBlobFixture creates a BlobFixture with custom fields.
func NewBlobFixture ¶
func NewBlobFixture() *BlobFixture
NewBlobFixture creates a randomly generated BlobFixture.
func SizedBlobFixture ¶
func SizedBlobFixture(size uint64, pieceLength uint64) *BlobFixture
SizedBlobFixture creates a randomly generated BlobFixture of given size with given piece lengths.
func (*BlobFixture) Length ¶
func (f *BlobFixture) Length() int64
Length returns the length of the blob.
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest can be represented in a string like "<algorithm>:<hex_digest_string>" Example:
sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
func DigestListFixture ¶
DigestListFixture returns a list of random Digests.
func NewSHA256DigestFromHex ¶
NewSHA256DigestFromHex constructs a Digest from a sha256 in hexadecimal format. Returns error if hex is not a valid sha256.
func ParseSHA256Digest ¶
ParseSHA256Digest parses a raw "<algo>:<hex>" sha256 digest. Returns error if the algo is not sha256 or the hex is not a valid sha256.
func (Digest) Hex ¶
Hex returns the hex part of the digest. Example:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
func (Digest) MarshalJSON ¶
MarshalJSON unmarshals hexBytes to Digest.
func (Digest) String ¶
String returns digest in string format like "<algorithm>:<hex_digest_string>".
func (*Digest) UnmarshalJSON ¶
UnmarshalJSON unmarshals "<algorithm>:<hex_digest_string>" to Digest.
type DigestList ¶
type DigestList []Digest
DigestList is a list of digests.
func (*DigestList) Scan ¶
func (l *DigestList) Scan(src interface{}) error
Scan unmarshals []byte to a list of Digest.
type Digester ¶
type Digester struct {
// contains filtered or unexported fields
}
Digester calculates the digest of data stream.
func NewDigester ¶
func NewDigester() *Digester
NewDigester instantiates and returns a new Digester object.
func (Digester) FromReader ¶
FromReader returns the digest of data from reader.
type InfoHash ¶
type InfoHash [20]byte
InfoHash is 20-byte SHA1 hash of the Info struct. It is the authoritative identifier for a torrent.
func InfoHashFixture ¶
func InfoHashFixture() InfoHash
InfoHashFixture returns a randomly generated InfoHash.
func NewInfoHashFromBytes ¶
NewInfoHashFromBytes converts raw bytes to an InfoHash.
func NewInfoHashFromHex ¶
NewInfoHashFromHex converts a hexidemical string into an InfoHash
type MetaInfo ¶
type MetaInfo struct {
// contains filtered or unexported fields
}
MetaInfo contains torrent metadata.
func DeserializeMetaInfo ¶
DeserializeMetaInfo reconstructs a MetaInfo from a json blob.
func MetaInfoFixture ¶
func MetaInfoFixture() *MetaInfo
MetaInfoFixture returns a randomly generated MetaInfo.
func NewMetaInfo ¶
NewMetaInfo creates a new MetaInfo. Assumes that d is the valid digest for blob (re-computing it is expensive).
func (*MetaInfo) GetPieceLength ¶
GetPieceLength returns the length of piece i.
func (*MetaInfo) GetPieceSum ¶
GetPieceSum returns the checksum of piece i. Does not check bounds.
func (*MetaInfo) PieceLength ¶
PieceLength returns the piece length used to break up the original blob. Note, the final piece may be shorter than this. Use GetPieceLength for the true lengths of each piece.
type PeerContext ¶
type PeerContext struct { // IP and Port specify the address the peer will announce itself as. Note, // this is distinct from the address a peer's Scheduler will listen on // because the peer may be running within a container and the address it // listens on is mapped to a different ip/port outside of the container. IP string `json:"ip"` Port int `json:"port"` // PeerID the peer will identify itself as. PeerID PeerID `json:"peer_id"` // Zone is the zone the peer is running within. Zone string `json:"zone"` // Cluster is the Kraken cluster the peer is running within. Cluster string `json:"cluster"` // Origin indicates whether the peer is an origin server or not. Origin bool `json:"origin"` }
PeerContext defines the context a peer runs within, namely the fields which are used to identify each peer.
func NewPeerContext ¶
func NewPeerContext( f PeerIDFactory, zone, cluster, ip string, port int, origin bool) (PeerContext, error)
NewPeerContext creates a new PeerContext.
func OriginContextFixture ¶
func OriginContextFixture() PeerContext
OriginContextFixture returns a randomly generated origin PeerContext.
func PeerContextFixture ¶
func PeerContextFixture() PeerContext
PeerContextFixture returns a randomly generated PeerContext.
type PeerID ¶
type PeerID [20]byte
PeerID represents a fixed size peer id.
func HashedPeerID ¶
HashedPeerID returns a PeerID derived from the hash of s.
func NewPeerID ¶
NewPeerID parses a PeerID from the given string. Must be in hexadecimal notation, encoding exactly 20 bytes.
func RandomPeerID ¶
RandomPeerID returns a randomly generated PeerID.
type PeerIDFactory ¶
type PeerIDFactory string
PeerIDFactory defines the method used to generate a peer id.
const AddrHashPeerIDFactory PeerIDFactory = "addr_hash"
AddrHashPeerIDFactory creates peers ids based on a full "ip:port" address.
const RandomPeerIDFactory PeerIDFactory = "random"
RandomPeerIDFactory creates random peer ids.
func (PeerIDFactory) GeneratePeerID ¶
func (f PeerIDFactory) GeneratePeerID(ip string, port int) (PeerID, error)
GeneratePeerID creates a new peer id per the factory policy.
type PeerInfo ¶
type PeerInfo struct { PeerID PeerID `json:"peer_id"` IP string `json:"ip"` Port int `json:"port"` Origin bool `json:"origin"` Complete bool `json:"complete"` }
PeerInfo defines peer metadata scoped to a torrent.
func NewPeerInfo ¶
NewPeerInfo creates a new PeerInfo.
func OriginPeerInfoFixture ¶
func OriginPeerInfoFixture() *PeerInfo
OriginPeerInfoFixture returns a randomly generated PeerInfo for an origin.
func PeerInfoFixture ¶
func PeerInfoFixture() *PeerInfo
PeerInfoFixture returns a randomly generated PeerInfo.
func PeerInfoFromContext ¶
func PeerInfoFromContext(pctx PeerContext, complete bool) *PeerInfo
PeerInfoFromContext derives PeerInfo from a PeerContext.
func SortedByPeerID ¶
SortedByPeerID returns a copy of peers which has been sorted by peer id.
type PeersByPeerID ¶
type PeersByPeerID struct{ PeerInfos }
PeersByPeerID sorts PeerInfos by peer id.