mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 05:59:55 +08:00
not quite working yet, but closer
This commit is contained in:
@ -158,8 +158,8 @@ func (dht *IpfsDHT) handleMessages() {
|
||||
}
|
||||
//
|
||||
|
||||
u.DOut("[peer: %s]", dht.self.ID.Pretty())
|
||||
u.DOut("Got message type: '%s' [id = %x, from = %s]",
|
||||
u.DOut("[peer: %s]\nGot message type: '%s' [id = %x, from = %s]",
|
||||
dht.self.ID.Pretty(),
|
||||
PBDHTMessage_MessageType_name[int32(pmes.GetType())],
|
||||
pmes.GetId(), mes.Peer.ID.Pretty())
|
||||
switch pmes.GetType() {
|
||||
@ -235,6 +235,7 @@ func (dht *IpfsDHT) putValueToNetwork(p *peer.Peer, key string, value []byte) er
|
||||
}
|
||||
|
||||
func (dht *IpfsDHT) handleGetValue(p *peer.Peer, pmes *PBDHTMessage) {
|
||||
u.DOut("handleGetValue for key: %s", pmes.GetKey())
|
||||
dskey := ds.NewKey(pmes.GetKey())
|
||||
resp := &DHTMessage{
|
||||
Response: true,
|
||||
|
@ -62,11 +62,22 @@ func (s *IpfsDHT) PutValue(key u.Key, value []byte) {
|
||||
func (s *IpfsDHT) GetValue(key u.Key, timeout time.Duration) ([]byte, error) {
|
||||
route_level := 0
|
||||
|
||||
// If we have it local, dont bother doing an RPC!
|
||||
// NOTE: this might not be what we want to do...
|
||||
val,err := s.GetLocal(key)
|
||||
if err != nil {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
p := s.routes[route_level].NearestPeer(kb.ConvertKey(key))
|
||||
if p == nil {
|
||||
return nil, kb.ErrLookupFailure
|
||||
}
|
||||
|
||||
if kb.Closer(s.self.ID, p.ID, key) {
|
||||
return nil, u.ErrNotFound
|
||||
}
|
||||
|
||||
for route_level < len(s.routes) && p != nil {
|
||||
pmes, err := s.getValueSingle(p, key, timeout, route_level)
|
||||
if err != nil {
|
||||
@ -84,17 +95,21 @@ func (s *IpfsDHT) GetValue(key u.Key, timeout time.Duration) ([]byte, error) {
|
||||
// We were given a closer node
|
||||
closers := pmes.GetPeers()
|
||||
if len(closers) > 0 {
|
||||
if peer.ID(closers[0].GetId()).Equal(s.self.ID) {
|
||||
return nil, u.ErrNotFound
|
||||
}
|
||||
maddr, err := ma.NewMultiaddr(closers[0].GetAddr())
|
||||
if err != nil {
|
||||
// ??? Move up route level???
|
||||
panic("not yet implemented")
|
||||
}
|
||||
|
||||
p, err = s.network.GetConnection(peer.ID(closers[0].GetId()), maddr)
|
||||
np, err := s.network.GetConnection(peer.ID(closers[0].GetId()), maddr)
|
||||
if err != nil {
|
||||
u.PErr("[%s] Failed to connect to: %s", s.self.ID.Pretty(), closers[0].GetAddr())
|
||||
route_level++
|
||||
}
|
||||
p = np
|
||||
} else {
|
||||
route_level++
|
||||
}
|
||||
@ -159,6 +174,9 @@ func (s *IpfsDHT) FindProviders(key u.Key, timeout time.Duration) ([]*peer.Peer,
|
||||
|
||||
var prov_arr []*peer.Peer
|
||||
for _, prov := range pmes_out.GetPeers() {
|
||||
if peer.ID(prov.GetId()).Equal(s.self.ID) {
|
||||
continue
|
||||
}
|
||||
p := s.network.Find(u.Key(prov.GetId()))
|
||||
if p == nil {
|
||||
u.DOut("given provider %s was not in our network already.", peer.ID(prov.GetId()).Pretty())
|
||||
|
@ -316,6 +316,10 @@ func (s *Swarm) GetConnection(id peer.ID, addr *ma.Multiaddr) (*peer.Peer, error
|
||||
Addresses: []*ma.Multiaddr{addr},
|
||||
}
|
||||
|
||||
if id.Equal(s.local.ID) {
|
||||
panic("Attempted connection to self!")
|
||||
}
|
||||
|
||||
conn, err, reused := s.Dial(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user