2018-07-19 15:48:08 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-08-23 16:20:11 +01:00
|
|
|
"github.com/zeebo/errs"
|
2018-07-19 15:48:08 +01:00
|
|
|
|
2018-10-08 16:09:37 +01:00
|
|
|
"storj.io/storj/pkg/dht"
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-08-23 16:20:11 +01:00
|
|
|
"storj.io/storj/pkg/pool"
|
2018-08-24 05:01:03 +01:00
|
|
|
"storj.io/storj/pkg/provider"
|
2018-07-19 15:48:08 +01:00
|
|
|
"storj.io/storj/pkg/transport"
|
|
|
|
)
|
|
|
|
|
2018-08-23 16:20:11 +01:00
|
|
|
//NodeClientErr is the class for all errors pertaining to node client operations
|
|
|
|
var NodeClientErr = errs.Class("node client error")
|
|
|
|
|
2018-07-19 15:48:08 +01:00
|
|
|
// NewNodeClient instantiates a node client
|
2018-10-08 16:09:37 +01:00
|
|
|
func NewNodeClient(identity *provider.FullIdentity, self pb.Node, dht dht.DHT) (Client, error) {
|
2018-08-24 05:01:03 +01:00
|
|
|
client := transport.NewClient(identity)
|
2018-07-19 15:48:08 +01:00
|
|
|
return &Node{
|
2018-10-08 16:09:37 +01:00
|
|
|
dht: dht,
|
2018-07-19 15:48:08 +01:00
|
|
|
self: self,
|
2018-08-24 05:01:03 +01:00
|
|
|
tc: client,
|
2018-07-19 15:48:08 +01:00
|
|
|
cache: pool.NewConnectionPool(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client is the Node client communication interface
|
|
|
|
type Client interface {
|
2018-09-18 05:39:06 +01:00
|
|
|
Lookup(ctx context.Context, to pb.Node, find pb.Node) ([]*pb.Node, error)
|
2018-07-19 15:48:08 +01:00
|
|
|
}
|