...

Source file src/github.com/containerd/ttrpc/handshake.go

Documentation: github.com/containerd/ttrpc

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package ttrpc
    18  
    19  import (
    20  	"context"
    21  	"net"
    22  )
    23  
    24  // Handshaker defines the interface for connection handshakes performed on the
    25  // server or client when first connecting.
    26  type Handshaker interface {
    27  	// Handshake should confirm or decorate a connection that may be incoming
    28  	// to a server or outgoing from a client.
    29  	//
    30  	// If this returns without an error, the caller should use the connection
    31  	// in place of the original connection.
    32  	//
    33  	// The second return value can contain credential specific data, such as
    34  	// unix socket credentials or TLS information.
    35  	//
    36  	// While we currently only have implementations on the server-side, this
    37  	// interface should be sufficient to implement similar handshakes on the
    38  	// client-side.
    39  	Handshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error)
    40  }
    41  
    42  type handshakerFunc func(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error)
    43  
    44  func (fn handshakerFunc) Handshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error) {
    45  	return fn(ctx, conn)
    46  }
    47  
    48  func noopHandshake(_ context.Context, conn net.Conn) (net.Conn, interface{}, error) {
    49  	return conn, nil, nil
    50  }
    51  

View as plain text