本文整理汇总了Golang中crypto/tls.Conn.LocalAddr方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.LocalAddr方法的具体用法?Golang Conn.LocalAddr怎么用?Golang Conn.LocalAddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crypto/tls.Conn
的用法示例。
在下文中一共展示了Conn.LocalAddr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tlsConnectionStateString
// tlsConnectionStateString выводит в лог информацию о TLS-соединении.
func tlsConnectionStateString(conn *tls.Conn) string {
var state = conn.ConnectionState()
return fmt.Sprint("Connection state:",
"\n------------------------------------------------------------",
"\n Local Address: ", conn.LocalAddr(),
"\n Remote Address: ", conn.RemoteAddr(),
"\n TLS version: ", state.Version,
"\n Handshake Complete: ", state.HandshakeComplete,
"\n Did Resume: ", state.DidResume,
"\n Cipher Suite: ", state.CipherSuite,
"\n------------------------------------------------------------")
}
示例2: testRoundTrip
func testRoundTrip(t *testing.T, proxy *server.Server, origin *originHandler, checkerFn func(conn net.Conn, proxy *server.Server, originURL *url.URL)) {
var conn net.Conn
var err error
addr := proxy.Addr.String()
if !proxy.Tls {
conn, err = net.Dial("tcp", addr)
log.Debugf("%s -> %s (via HTTP) -> %s", conn.LocalAddr().String(), addr, origin.server.URL)
if !assert.NoError(t, err, "should dial proxy server") {
t.FailNow()
}
} else {
var tlsConn *tls.Conn
x509cert := serverCertificate.X509()
tlsConn, err = tls.Dial("tcp", addr, &tls.Config{
CipherSuites: preferredCipherSuites,
InsecureSkipVerify: true,
})
log.Debugf("%s -> %s (via HTTPS) -> %s", tlsConn.LocalAddr().String(), addr, origin.server.URL)
if !assert.NoError(t, err, "should dial proxy server") {
t.FailNow()
}
conn = tlsConn
if !tlsConn.ConnectionState().PeerCertificates[0].Equal(x509cert) {
if err := tlsConn.Close(); err != nil {
log.Errorf("Error closing chained server connection: %s", err)
}
t.Fatal("Server's certificate didn't match expected")
}
}
defer func() {
assert.NoError(t, conn.Close(), "should close connection")
}()
url, _ := url.Parse(origin.server.URL)
checkerFn(conn, proxy, url)
}