2019-09-10 17:05:07 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/rpc"
|
|
|
|
"storj.io/common/storj"
|
2019-09-10 17:05:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type client struct {
|
2019-09-19 05:46:39 +01:00
|
|
|
conn *rpc.Conn
|
2019-12-22 14:52:55 +00:00
|
|
|
client pb.DRPCContactClient
|
2019-09-10 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// dialNodeURL dials the target contact endpoint.
|
2020-05-19 17:42:00 +01:00
|
|
|
func dialNodeURL(ctx context.Context, dialer rpc.Dialer, nodeurl storj.NodeURL) (*client, error) {
|
|
|
|
conn, err := dialer.DialNodeURL(ctx, nodeurl)
|
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,
|
2020-03-25 12:15:27 +00:00
|
|
|
client: pb.NewDRPCContactClient(conn),
|
2019-09-10 17:05:07 +01:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Close closes the connection.
|
2019-09-19 05:46:39 +01:00
|
|
|
func (client *client) Close() error {
|
2019-09-10 17:05:07 +01:00
|
|
|
return client.conn.Close()
|
|
|
|
}
|