mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00
fix publish fail on prexisting bad record
dont error out if prexisting record is bad, just grab its sequence number and continue on with the publish. License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -4,12 +4,15 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
|
||||
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
|
||||
ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
key "github.com/ipfs/go-ipfs/blocks/key"
|
||||
peer "github.com/ipfs/go-ipfs/p2p/peer"
|
||||
routing "github.com/ipfs/go-ipfs/routing"
|
||||
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
|
||||
u "github.com/ipfs/go-ipfs/util"
|
||||
"github.com/ipfs/go-ipfs/util/testutil"
|
||||
logging "github.com/ipfs/go-ipfs/vendor/go-log-v1.0.0"
|
||||
)
|
||||
@ -25,7 +28,16 @@ type client struct {
|
||||
// FIXME(brian): is this method meant to simulate putting a value into the network?
|
||||
func (c *client) PutValue(ctx context.Context, key key.Key, val []byte) error {
|
||||
log.Debugf("PutValue: %s", key)
|
||||
return c.datastore.Put(key.DsKey(), val)
|
||||
rec := new(dhtpb.Record)
|
||||
rec.Value = val
|
||||
rec.Key = proto.String(string(key))
|
||||
rec.TimeReceived = proto.String(u.FormatRFC3339(time.Now()))
|
||||
data, err := proto.Marshal(rec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.datastore.Put(key.DsKey(), data)
|
||||
}
|
||||
|
||||
// FIXME(brian): is this method meant to simulate getting a value from the network?
|
||||
@ -41,19 +53,20 @@ func (c *client) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
|
||||
return nil, errors.New("could not cast value from datastore")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (c *client) GetValues(ctx context.Context, key key.Key, count int) ([]routing.RecvdVal, error) {
|
||||
log.Debugf("GetValue: %s", key)
|
||||
v, err := c.datastore.Get(key.DsKey())
|
||||
rec := new(dhtpb.Record)
|
||||
err = proto.Unmarshal(data, rec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, ok := v.([]byte)
|
||||
if !ok {
|
||||
return nil, errors.New("could not cast value from datastore")
|
||||
return rec.GetValue(), nil
|
||||
}
|
||||
|
||||
func (c *client) GetValues(ctx context.Context, key key.Key, count int) ([]routing.RecvdVal, error) {
|
||||
log.Debugf("GetValues: %s", key)
|
||||
data, err := c.GetValue(ctx, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return []routing.RecvdVal{{Val: data, From: c.peer.ID()}}, nil
|
||||
|
Reference in New Issue
Block a user