storj/satellite/contact/client.go
Jess G d3ef574b20 pkg/pb: minor changes to contact.proto (#3048)
* minor fixes to contact proto

* simply and rm nodeAddr object from client
2019-09-13 19:37:32 -05:00

52 lines
1.3 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package contact
import (
"context"
"google.golang.org/grpc"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/peertls/tlsopts"
"storj.io/storj/pkg/storj"
"storj.io/storj/pkg/transport"
)
type client struct {
conn *grpc.ClientConn
client pb.ContactClient
}
// newClient dials the target contact endpoint
func newClient(ctx context.Context, transport transport.Client, targetAddress string, peerIDFromContext storj.NodeID) (*client, error) {
opts, err := tlsopts.NewOptions(transport.Identity(), tlsopts.Config{PeerIDVersions: "latest"}, nil)
if err != nil {
return nil, Error.Wrap(err)
}
dialOption, err := opts.DialOption(peerIDFromContext)
if err != nil {
return nil, Error.Wrap(err)
}
conn, err := transport.DialAddress(ctx, targetAddress, dialOption)
if err != nil {
return nil, Error.Wrap(err)
}
return &client{
conn: conn,
client: pb.NewContactClient(conn),
}, nil
}
// pingNode pings a node
func (client *client) pingNode(ctx context.Context, req *pb.ContactPingRequest, opt grpc.CallOption) (*pb.ContactPingResponse, error) {
return client.client.PingNode(ctx, req, opt)
}
// close closes the connection
func (client *client) close() error {
return client.conn.Close()
}