fixed a few channel lockups, fixed announced port in dht, successfully announced and served a blob
This commit is contained in:
parent
47a732688d
commit
1c2175df39
3 changed files with 31 additions and 18 deletions
17
dht/dht.go
17
dht/dht.go
|
@ -3,16 +3,19 @@ package dht
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/reflector.go/dht/bits"
|
||||
peerproto "github.com/lbryio/reflector.go/peer"
|
||||
|
||||
"github.com/lbryio/lbry.go/errors"
|
||||
"github.com/lbryio/lbry.go/stopOnce"
|
||||
"github.com/lbryio/reflector.go/dht/bits"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -21,7 +24,8 @@ func init() {
|
|||
}
|
||||
|
||||
const (
|
||||
Network = "udp4"
|
||||
Network = "udp4"
|
||||
DefaultPort = 4444
|
||||
|
||||
// TODO: all these constants should be defaults, and should be used to set values in the standard Config. then the code should use values in the config
|
||||
// TODO: alternatively, have a global Config for constants. at least that way tests can modify the values
|
||||
|
@ -57,17 +61,20 @@ type Config struct {
|
|||
NodeID string
|
||||
// print the state of the dht every X time
|
||||
PrintState time.Duration
|
||||
// the port that clients can use to download blobs using the LBRY peer protocol
|
||||
PeerProtocolPort int
|
||||
}
|
||||
|
||||
// NewStandardConfig returns a Config pointer with default values.
|
||||
func NewStandardConfig() *Config {
|
||||
return &Config{
|
||||
Address: "0.0.0.0:4444",
|
||||
Address: "0.0.0.0:" + strconv.Itoa(DefaultPort),
|
||||
SeedNodes: []string{
|
||||
"lbrynet1.lbry.io:4444",
|
||||
"lbrynet2.lbry.io:4444",
|
||||
"lbrynet3.lbry.io:4444",
|
||||
},
|
||||
PeerProtocolPort: peerproto.DefaultPort,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,7 +337,7 @@ func (dht *DHT) storeOnNode(hash bits.Bitmap, c Contact) {
|
|||
Value: storeArgsValue{
|
||||
Token: res.Token,
|
||||
LbryID: dht.contact.ID,
|
||||
Port: dht.contact.Port,
|
||||
Port: dht.conf.PeerProtocolPort,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
@ -299,7 +299,11 @@ func (n *Node) handleRequest(addr *net.UDPAddr, request Request) {
|
|||
func (n *Node) handleResponse(addr *net.UDPAddr, response Response) {
|
||||
tx := n.txFind(response.ID, Contact{ID: response.NodeID, IP: addr.IP, Port: addr.Port})
|
||||
if tx != nil {
|
||||
tx.res <- response
|
||||
select {
|
||||
case tx.res <- response:
|
||||
default:
|
||||
log.Errorf("[%s] query %s: response received but tx has no listener", n.id.HexShort(), response.ID.HexShort())
|
||||
}
|
||||
}
|
||||
|
||||
n.rt.Update(Contact{ID: response.NodeID, IP: addr.IP, Port: addr.Port})
|
||||
|
|
|
@ -69,13 +69,13 @@ func (cf *contactFinder) Stop() {
|
|||
|
||||
func (cf *contactFinder) Find() ([]Contact, bool, error) {
|
||||
if cf.findValue {
|
||||
log.Debugf("[%s] starting an iterative Find for the value %s", cf.node.id.HexShort(), cf.target.HexShort())
|
||||
log.Debugf("[%s] find %s: starting iterativeFindValue", cf.node.id.HexShort(), cf.target.HexShort())
|
||||
} else {
|
||||
log.Debugf("[%s] starting an iterative Find for contacts near %s", cf.node.id.HexShort(), cf.target.HexShort())
|
||||
log.Debugf("[%s] find %s: starting iterativeFindNode", cf.node.id.HexShort(), cf.target.HexShort())
|
||||
}
|
||||
cf.appendNewToShortlist(cf.node.rt.GetClosest(cf.target, alpha))
|
||||
if len(cf.shortlist) == 0 {
|
||||
return nil, false, errors.Err("no contacts in routing table")
|
||||
return nil, false, errors.Err("[%s] find %s: no contacts in routing table", cf.node.id.HexShort(), cf.target.HexShort())
|
||||
}
|
||||
|
||||
for i := 0; i < alpha; i++ {
|
||||
|
@ -108,14 +108,16 @@ func (cf *contactFinder) Find() ([]Contact, bool, error) {
|
|||
}
|
||||
|
||||
func (cf *contactFinder) iterationWorker(num int) {
|
||||
log.Debugf("[%s] starting worker %d", cf.node.id.HexShort(), num)
|
||||
defer func() { log.Debugf("[%s] stopping worker %d", cf.node.id.HexShort(), num) }()
|
||||
log.Debugf("[%s] find %s: starting worker %d", cf.node.id.HexShort(), cf.target.HexShort(), num)
|
||||
defer func() {
|
||||
log.Debugf("[%s] find %s: stopping worker %d", cf.node.id.HexShort(), cf.target.HexShort(), num)
|
||||
}()
|
||||
|
||||
for {
|
||||
maybeContact := cf.popFromShortlist()
|
||||
if maybeContact == nil {
|
||||
// TODO: block if there are pending requests out from other workers. there may be more shortlist values coming
|
||||
log.Debugf("[%s] worker %d: no contacts in shortlist, waiting...", cf.node.id.HexShort(), num)
|
||||
//log.Debugf("[%s] worker %d: no contacts in shortlist, waiting...", cf.node.id.HexShort(), num)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
} else {
|
||||
contact := *maybeContact
|
||||
|
@ -131,7 +133,7 @@ func (cf *contactFinder) iterationWorker(num int) {
|
|||
req.Method = findNodeMethod
|
||||
}
|
||||
|
||||
log.Debugf("[%s] worker %d: contacting %s", cf.node.id.HexShort(), num, contact.ID.HexShort())
|
||||
log.Debugf("[%s] find %s: worker %d: contacting %s", cf.node.id.HexShort(), cf.target.HexShort(), num, contact.ID.HexShort())
|
||||
|
||||
cf.incrementOutstanding()
|
||||
|
||||
|
@ -140,23 +142,23 @@ func (cf *contactFinder) iterationWorker(num int) {
|
|||
select {
|
||||
case res = <-resCh:
|
||||
case <-cf.stop.Ch():
|
||||
log.Debugf("[%s] worker %d: canceled", cf.node.id.HexShort(), num)
|
||||
log.Debugf("[%s] find %s: worker %d: canceled", cf.node.id.HexShort(), cf.target.HexShort(), num)
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
// nothing to do, response timed out
|
||||
log.Debugf("[%s] worker %d: search canceled or timed out waiting for %s", cf.node.id.HexShort(), num, contact.ID.HexShort())
|
||||
log.Debugf("[%s] find %s: worker %d: search canceled or timed out waiting for %s", cf.node.id.HexShort(), cf.target.HexShort(), num, contact.ID.HexShort())
|
||||
} else if cf.findValue && res.FindValueKey != "" {
|
||||
log.Debugf("[%s] worker %d: got value", cf.node.id.HexShort(), num)
|
||||
log.Debugf("[%s] find %s: worker %d: got value", cf.node.id.HexShort(), cf.target.HexShort(), num)
|
||||
cf.findValueMutex.Lock()
|
||||
cf.findValueResult = res.Contacts
|
||||
cf.findValueMutex.Unlock()
|
||||
cf.stop.Stop()
|
||||
return
|
||||
} else {
|
||||
log.Debugf("[%s] worker %d: got contacts", cf.node.id.HexShort(), num)
|
||||
log.Debugf("[%s] find %s: worker %d: got contacts", cf.node.id.HexShort(), cf.target.HexShort(), num)
|
||||
cf.insertIntoActiveList(contact)
|
||||
cf.appendNewToShortlist(res.Contacts)
|
||||
}
|
||||
|
@ -165,7 +167,7 @@ func (cf *contactFinder) iterationWorker(num int) {
|
|||
}
|
||||
|
||||
if cf.isSearchFinished() {
|
||||
log.Debugf("[%s] worker %d: search is finished", cf.node.id.HexShort(), num)
|
||||
log.Debugf("[%s] find %s: worker %d: search is finished", cf.node.id.HexShort(), cf.target.HexShort(), num)
|
||||
cf.stop.Stop()
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue