2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-07-19 15:48:08 +01:00
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-08-23 16:20:11 +01:00
|
|
|
"github.com/zeebo/errs"
|
2018-11-29 18:39:27 +00: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-24 05:01:03 +01:00
|
|
|
"storj.io/storj/pkg/provider"
|
2018-12-22 04:51:42 +00:00
|
|
|
"storj.io/storj/pkg/transport"
|
2018-07-19 15:48:08 +01:00
|
|
|
)
|
|
|
|
|
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-12-22 04:51:42 +00:00
|
|
|
func NewNodeClient(identity *provider.FullIdentity, self pb.Node, dht dht.DHT, obs ...transport.Observer) (Client, error) {
|
2018-10-26 15:07:02 +01:00
|
|
|
node := &Node{
|
2018-10-26 17:38:22 +01:00
|
|
|
dht: dht,
|
|
|
|
self: self,
|
2018-12-22 04:51:42 +00:00
|
|
|
pool: NewConnectionPool(identity, obs...),
|
2018-10-26 15:07:02 +01:00
|
|
|
}
|
2018-10-26 17:38:22 +01:00
|
|
|
|
|
|
|
node.pool.Init()
|
|
|
|
|
2018-10-26 15:07:02 +01:00
|
|
|
return node, nil
|
2018-07-19 15:48:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-10-26 17:38:22 +01:00
|
|
|
Ping(ctx context.Context, to pb.Node) (bool, error)
|
2018-10-26 15:07:02 +01:00
|
|
|
Disconnect() error
|
2018-07-19 15:48:08 +01:00
|
|
|
}
|