Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
8417c9ff
Commit
8417c9ff
authored
Jan 05, 2016
by
Richer Maximilien
Browse files
Client lib
Fix addr & port in dialing
parent
460ede94
Pipeline
#140
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
net/client.go
0 → 100644
View file @
8417c9ff
package
net
import
(
"crypto/tls"
"crypto/x509"
"flag"
"io/ioutil"
"log"
"math/rand"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)
// Connect to a peer
//
// Closing must be defered after call
func
Connect
(
addr_port
string
,
cert
,
key
,
ca
[]
byte
)
*
ClientConn
{
// load peer cert/key, ca as PEM buffers
peerCert
,
err
:=
tls
.
X509KeyPair
(
cert
,
key
)
if
err
!=
nil
{
log
.
Fatal
(
"Load peer cert/key error: %v"
,
err
)
}
caCertPool
:=
x509
.
NewCertPool
()
caCertPool
.
AppendCertsFromPEM
(
ca
)
// configure transport authentificator
ta
:=
credentials
.
NewTLS
(
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
peerCert
},
RootCAs
:
caCertPool
,
})
// let's do the dialing !
con
,
err
:=
grpc
.
Dial
(
addr_port
,
grpc
.
WithTransportCredentials
(
ta
))
if
err
!=
nil
{
grpclog
.
Fatalf
(
"Fail to dial: %v"
,
err
)
}
return
con
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment