storj/pkg/transport/transport.go
Maximillian von Briesen 553def620a TLS Support (#252)
* begin adding tls

* remove incomplete line in gw/main.go

* identity fixes+:

+ fix `peertls.NewCert` public key issue
+ fix `peertls.verfiyChain` issue
+ fix identity dial option
+ rename `GenerateCA` to `NewCA` and `generateCAWorker` to `newCAWorker` for better consistency/convention

* use pdbclient instead of pointerdb in miniogw

* fix tests

* go fmt

* make review changes

* modify how context.Background() is used

* more context stuff
2018-08-23 22:01:03 -06:00

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/provider"
proto "storj.io/storj/protos/overlay"
)
// 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 *proto.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 proto.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())
}