b6b6111173
* protos: move streams to pb * protos: move overlay to pb * protos: move pointerdb to pb * protos: move piecestore to pb * fix statdb import naming
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package transport
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"storj.io/storj/pkg/pb"
|
|
"storj.io/storj/pkg/provider"
|
|
)
|
|
|
|
// Transport interface structure
|
|
type Transport struct {
|
|
identity *provider.FullIdentity
|
|
}
|
|
|
|
// NewClient returns a newly instantiated Transport Client
|
|
func NewClient(identity *provider.FullIdentity) *Transport {
|
|
return &Transport{identity: identity}
|
|
}
|
|
|
|
// DialNode using the authenticated mode
|
|
func (o *Transport) DialNode(ctx context.Context, node *pb.Node) (conn *grpc.ClientConn, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
if node.Address == nil || node.Address.Address == "" {
|
|
return nil, Error.New("no address")
|
|
}
|
|
|
|
dialOpt, err := o.identity.DialOption()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return grpc.Dial(node.Address.Address, dialOpt)
|
|
}
|
|
|
|
// DialUnauthenticated using unauthenticated mode
|
|
func (o *Transport) DialUnauthenticated(ctx context.Context, addr pb.NodeAddress) (conn *grpc.ClientConn, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
if addr.Address == "" {
|
|
return nil, Error.New("no address")
|
|
}
|
|
|
|
return grpc.Dial(addr.Address, grpc.WithInsecure())
|
|
}
|