2019-09-10 17:05:07 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/pb"
|
2019-09-19 05:46:39 +01:00
|
|
|
"storj.io/storj/pkg/rpc"
|
2019-09-10 17:05:07 +01:00
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
)
|
|
|
|
|
|
|
|
type client struct {
|
2019-09-19 05:46:39 +01:00
|
|
|
conn *rpc.Conn
|
|
|
|
client rpc.ContactClient
|
2019-09-10 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// newClient dials the target contact endpoint
|
2019-09-19 05:46:39 +01:00
|
|
|
func newClient(ctx context.Context, dialer rpc.Dialer, address string, id storj.NodeID) (*client, error) {
|
|
|
|
conn, err := dialer.DialAddressID(ctx, address, id)
|
2019-09-10 17:05:07 +01:00
|
|
|
if err != nil {
|
2019-09-19 05:46:39 +01:00
|
|
|
return nil, err
|
2019-09-10 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return &client{
|
|
|
|
conn: conn,
|
2019-09-19 05:46:39 +01:00
|
|
|
client: conn.ContactClient(),
|
2019-09-10 17:05:07 +01:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// pingNode pings a node
|
2019-09-19 05:46:39 +01:00
|
|
|
func (client *client) pingNode(ctx context.Context, req *pb.ContactPingRequest) (*pb.ContactPingResponse, error) {
|
|
|
|
return client.client.PingNode(ctx, req)
|
2019-09-10 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
// Close closes the connection
|
|
|
|
func (client *client) Close() error {
|
2019-09-10 17:05:07 +01:00
|
|
|
return client.conn.Close()
|
|
|
|
}
|