mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 17:22:21 +08:00
add put and get dht commands to cli
This commit is contained in:
@ -59,6 +59,11 @@ func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error
|
||||
wg.Add(1)
|
||||
go func(p peer.ID) {
|
||||
defer wg.Done()
|
||||
notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
|
||||
Type: notif.Value,
|
||||
ID: p,
|
||||
})
|
||||
|
||||
err := dht.putValueToPeer(ctx, p, key, rec)
|
||||
if err != nil {
|
||||
log.Debugf("failed putting value to peer: %s", err)
|
||||
@ -92,6 +97,11 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
|
||||
|
||||
// setup the Query
|
||||
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
|
||||
notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
|
||||
Type: notif.SendingQuery,
|
||||
ID: p,
|
||||
})
|
||||
|
||||
val, peers, err := dht.getValueOrPeers(ctx, p, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -102,6 +112,12 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
|
||||
res.success = true
|
||||
}
|
||||
|
||||
notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
|
||||
Type: notif.PeerResponse,
|
||||
ID: p,
|
||||
Responses: pointerizePeerInfos(peers),
|
||||
})
|
||||
|
||||
return res, nil
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user