...

Source file src/go.mongodb.org/mongo-driver/x/mongo/driver/topology/tls_connection_source_1_17.go

Documentation: go.mongodb.org/mongo-driver/x/mongo/driver/topology

     1  // Copyright (C) MongoDB, Inc. 2022-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  //go:build go1.17
     8  // +build go1.17
     9  
    10  package topology
    11  
    12  import (
    13  	"context"
    14  	"crypto/tls"
    15  	"net"
    16  )
    17  
    18  type tlsConn interface {
    19  	net.Conn
    20  
    21  	// Require HandshakeContext on the interface for Go 1.17 and higher.
    22  	HandshakeContext(ctx context.Context) error
    23  	ConnectionState() tls.ConnectionState
    24  }
    25  
    26  var _ tlsConn = (*tls.Conn)(nil)
    27  
    28  type tlsConnectionSource interface {
    29  	Client(net.Conn, *tls.Config) tlsConn
    30  }
    31  
    32  type tlsConnectionSourceFn func(net.Conn, *tls.Config) tlsConn
    33  
    34  var _ tlsConnectionSource = (tlsConnectionSourceFn)(nil)
    35  
    36  func (t tlsConnectionSourceFn) Client(nc net.Conn, cfg *tls.Config) tlsConn {
    37  	return t(nc, cfg)
    38  }
    39  
    40  var defaultTLSConnectionSource tlsConnectionSourceFn = func(nc net.Conn, cfg *tls.Config) tlsConn {
    41  	return tls.Client(nc, cfg)
    42  }
    43  
    44  // clientHandshake will perform a handshake on Go 1.17 and higher with HandshakeContext.
    45  func clientHandshake(ctx context.Context, client tlsConn) error {
    46  	return client.HandshakeContext(ctx)
    47  }
    48  

View as plain text