Generate default peerExtensionBytes using helpers
This commit is contained in:
parent
738a75bc1c
commit
085e676ef0
|
@ -278,7 +278,7 @@ func NewClient(cfg *Config) (cl *Client, err error) {
|
||||||
} else {
|
} else {
|
||||||
cl.downloadLimit = cfg.DownloadRateLimiter
|
cl.downloadLimit = cfg.DownloadRateLimiter
|
||||||
}
|
}
|
||||||
missinggo.CopyExact(&cl.extensionBytes, defaultExtensionBytes)
|
cl.extensionBytes = defaultPeerExtensionBytes()
|
||||||
cl.event.L = &cl.mu
|
cl.event.L = &cl.mu
|
||||||
storageImpl := cfg.DefaultStorage
|
storageImpl := cfg.DefaultStorage
|
||||||
if storageImpl == nil {
|
if storageImpl == nil {
|
||||||
|
|
17
global.go
17
global.go
|
@ -10,25 +10,16 @@ const (
|
||||||
maxRequests = 250 // Maximum pending requests we allow peers to send us.
|
maxRequests = 250 // Maximum pending requests we allow peers to send us.
|
||||||
defaultChunkSize = 0x4000 // 16KiB
|
defaultChunkSize = 0x4000 // 16KiB
|
||||||
|
|
||||||
// Justification for set bits follows.
|
|
||||||
//
|
|
||||||
// Extension protocol ([5]|=0x10):
|
|
||||||
// http://www.bittorrent.org/beps/bep_0010.html
|
|
||||||
//
|
|
||||||
// Fast Extension ([7]|=0x04):
|
|
||||||
// http://bittorrent.org/beps/bep_0006.html.
|
|
||||||
// Disabled until AllowedFast is implemented. TODO
|
|
||||||
//
|
|
||||||
// DHT ([7]|=1):
|
|
||||||
// http://www.bittorrent.org/beps/bep_0005.html
|
|
||||||
defaultExtensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x01"
|
|
||||||
|
|
||||||
// These are our extended message IDs. Peers will use these values to
|
// These are our extended message IDs. Peers will use these values to
|
||||||
// select which extension a message is intended for.
|
// select which extension a message is intended for.
|
||||||
metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
|
metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
|
||||||
pexExtendedId
|
pexExtendedId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func defaultPeerExtensionBytes() peerExtensionBytes {
|
||||||
|
return newPeerExtensionBytes(ExtensionBitDHT, ExtensionBitExtended)
|
||||||
|
}
|
||||||
|
|
||||||
// I could move a lot of these counters to their own file, but I suspect they
|
// I could move a lot of these counters to their own file, but I suspect they
|
||||||
// may be attached to a Client someday.
|
// may be attached to a Client someday.
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -38,6 +38,13 @@ type (
|
||||||
peerExtensionBytes [8]byte
|
peerExtensionBytes [8]byte
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func newPeerExtensionBytes(bits ...ExtensionBit) (ret peerExtensionBytes) {
|
||||||
|
for _, b := range bits {
|
||||||
|
ret.SetBit(b)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (pex peerExtensionBytes) SupportsExtended() bool {
|
func (pex peerExtensionBytes) SupportsExtended() bool {
|
||||||
return pex.GetBit(ExtensionBitExtended)
|
return pex.GetBit(ExtensionBitExtended)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
func TestDefaultExtensionBytes(t *testing.T) {
|
func TestDefaultExtensionBytes(t *testing.T) {
|
||||||
var pex peerExtensionBytes
|
var pex peerExtensionBytes
|
||||||
missinggo.CopyExact(&pex, defaultExtensionBytes)
|
missinggo.CopyExact(&pex, defaultPeerExtensionBytes())
|
||||||
assert.True(t, pex.SupportsDHT())
|
assert.True(t, pex.SupportsDHT())
|
||||||
assert.True(t, pex.SupportsExtended())
|
assert.True(t, pex.SupportsExtended())
|
||||||
assert.False(t, pex.SupportsFast())
|
assert.False(t, pex.SupportsFast())
|
||||||
|
|
Loading…
Reference in New Issue