forked from cerc-io/ipld-eth-server
Update vendor directory and make necessary code changes
Fixes for new geth version
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 IPFS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// Package nilrouting implements a routing client that does nothing.
|
||||
package nilrouting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/routing"
|
||||
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
)
|
||||
|
||||
type nilclient struct {
|
||||
}
|
||||
|
||||
func (c *nilclient) PutValue(_ context.Context, _ string, _ []byte, _ ...routing.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *nilclient) GetValue(_ context.Context, _ string, _ ...routing.Option) ([]byte, error) {
|
||||
return nil, errors.New("tried GetValue from nil routing")
|
||||
}
|
||||
|
||||
func (c *nilclient) SearchValue(_ context.Context, _ string, _ ...routing.Option) (<-chan []byte, error) {
|
||||
return nil, errors.New("tried SearchValue from nil routing")
|
||||
}
|
||||
|
||||
func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (peer.AddrInfo, error) {
|
||||
return peer.AddrInfo{}, nil
|
||||
}
|
||||
|
||||
func (c *nilclient) FindProvidersAsync(_ context.Context, _ cid.Cid, _ int) <-chan peer.AddrInfo {
|
||||
out := make(chan peer.AddrInfo)
|
||||
defer close(out)
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *nilclient) Provide(_ context.Context, _ cid.Cid, _ bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *nilclient) Bootstrap(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConstructNilRouting creates an Routing client which does nothing.
|
||||
func ConstructNilRouting(_ context.Context, _ host.Host, _ ds.Batching, _ record.Validator) (routing.Routing, error) {
|
||||
return &nilclient{}, nil
|
||||
}
|
||||
|
||||
// ensure nilclient satisfies interface
|
||||
var _ routing.Routing = &nilclient{}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
// Package offline implements Routing with a client which
|
||||
// is only able to perform offline operations.
|
||||
package offline
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/routing"
|
||||
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
pb "github.com/libp2p/go-libp2p-record/pb"
|
||||
)
|
||||
|
||||
// ErrOffline is returned when trying to perform operations that
|
||||
// require connectivity.
|
||||
var ErrOffline = errors.New("routing system in offline mode")
|
||||
|
||||
// NewOfflineRouter returns an Routing implementation which only performs
|
||||
// offline operations. It allows to Put and Get signed dht
|
||||
// records to and from the local datastore.
|
||||
func NewOfflineRouter(dstore ds.Datastore, validator record.Validator) routing.Routing {
|
||||
return &offlineRouting{
|
||||
datastore: dstore,
|
||||
validator: validator,
|
||||
}
|
||||
}
|
||||
|
||||
// offlineRouting implements the Routing interface,
|
||||
// but only provides the capability to Put and Get signed dht
|
||||
// records to and from the local datastore.
|
||||
type offlineRouting struct {
|
||||
datastore ds.Datastore
|
||||
validator record.Validator
|
||||
}
|
||||
|
||||
func (c *offlineRouting) PutValue(ctx context.Context, key string, val []byte, _ ...routing.Option) error {
|
||||
if err := c.validator.Validate(key, val); err != nil {
|
||||
return err
|
||||
}
|
||||
if old, err := c.GetValue(ctx, key); err == nil {
|
||||
// be idempotent to be nice.
|
||||
if bytes.Equal(old, val) {
|
||||
return nil
|
||||
}
|
||||
// check to see if the older record is better
|
||||
i, err := c.validator.Select(key, [][]byte{val, old})
|
||||
if err != nil {
|
||||
// this shouldn't happen for validated records.
|
||||
return err
|
||||
}
|
||||
if i != 0 {
|
||||
return errors.New("can't replace a newer record with an older one")
|
||||
}
|
||||
}
|
||||
rec := record.MakePutRecord(key, val)
|
||||
data, err := proto.Marshal(rec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.datastore.Put(dshelp.NewKeyFromBinary([]byte(key)), data)
|
||||
}
|
||||
|
||||
func (c *offlineRouting) GetValue(ctx context.Context, key string, _ ...routing.Option) ([]byte, error) {
|
||||
buf, err := c.datastore.Get(dshelp.NewKeyFromBinary([]byte(key)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rec := new(pb.Record)
|
||||
err = proto.Unmarshal(buf, rec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
val := rec.GetValue()
|
||||
|
||||
err = c.validator.Validate(key, val)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func (c *offlineRouting) SearchValue(ctx context.Context, key string, _ ...routing.Option) (<-chan []byte, error) {
|
||||
out := make(chan []byte, 1)
|
||||
go func() {
|
||||
defer close(out)
|
||||
v, err := c.GetValue(ctx, key)
|
||||
if err == nil {
|
||||
out <- v
|
||||
}
|
||||
}()
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *offlineRouting) FindPeer(ctx context.Context, pid peer.ID) (peer.AddrInfo, error) {
|
||||
return peer.AddrInfo{}, ErrOffline
|
||||
}
|
||||
|
||||
func (c *offlineRouting) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <-chan peer.AddrInfo {
|
||||
out := make(chan peer.AddrInfo)
|
||||
close(out)
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *offlineRouting) Provide(_ context.Context, k cid.Cid, _ bool) error {
|
||||
return ErrOffline
|
||||
}
|
||||
|
||||
func (c *offlineRouting) Ping(ctx context.Context, p peer.ID) (time.Duration, error) {
|
||||
return 0, ErrOffline
|
||||
}
|
||||
|
||||
func (c *offlineRouting) Bootstrap(context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ensure offlineRouting matches the Routing interface
|
||||
var _ routing.Routing = &offlineRouting{}
|
||||
Reference in New Issue
Block a user