google.golang.org/grpc@v1.72.2/xds/internal/xdsclient/transport/transport_interface.go (about) 1 /* 2 * 3 * Copyright 2024 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 // Package transport defines the interface that describe the functionality 19 // required to communicate with an xDS server using streaming calls. 20 package transport 21 22 import ( 23 "context" 24 25 "google.golang.org/grpc/internal/xds/bootstrap" 26 ) 27 28 // Builder is an interface for building a new xDS transport. 29 type Builder interface { 30 // Build creates a new xDS transport with the provided options. 31 Build(opts BuildOptions) (Transport, error) 32 } 33 34 // BuildOptions contains the options for building a new xDS transport. 35 type BuildOptions struct { 36 // ServerConfig contains the configuration that controls how the transport 37 // interacts with the xDS server. This includes the server URI and the 38 // credentials to use to connect to the server, among other things. 39 ServerConfig *bootstrap.ServerConfig 40 } 41 42 // Transport provides the functionality to communicate with an xDS server using 43 // streaming calls. 44 type Transport interface { 45 // CreateStreamingCall creates a new streaming call to the xDS server for the 46 // specified method name. The returned StreamingCall interface can be used to 47 // send and receive messages on the stream. 48 CreateStreamingCall(context.Context, string) (StreamingCall, error) 49 50 // Close closes the underlying connection and cleans up any resources used by the 51 // Transport. 52 Close() error 53 } 54 55 // StreamingCall is an interface that provides a way to send and receive 56 // messages on a stream. The methods accept or return any.Any messages instead 57 // of concrete types to allow this interface to be used for both ADS and LRS. 58 type StreamingCall interface { 59 // Send sends the provided message on the stream. 60 Send(any) error 61 62 // Recv block until the next message is received on the stream. 63 Recv() (any, error) 64 }