@@ -26,8 +26,6 @@ import (
26
26
//
27
27
// See NewTunnelServiceHandler.
28
28
type TunnelServiceHandler struct {
29
- tunnelpb.UnimplementedTunnelServiceServer
30
-
31
29
handlers grpchan.HandlerMap
32
30
noReverseTunnels bool
33
31
onReverseTunnelConnect func (TunnelChannel )
@@ -96,6 +94,14 @@ func (s *TunnelServiceHandler) RegisterService(desc *grpc.ServiceDesc, srv inter
96
94
s .handlers .RegisterService (desc , srv )
97
95
}
98
96
97
+ // Service returns the actual tunnel service implementation to register with a
98
+ // [grpc.ServiceRegistrar].
99
+ func (s * TunnelServiceHandler ) Service () tunnelpb.TunnelServiceServer {
100
+ return & tunnelServiceHandler {
101
+ h : s ,
102
+ }
103
+ }
104
+
99
105
// InitiateShutdown starts the graceful shutdown process and returns
100
106
// immediately. This should be called when the server wants to shut down. This
101
107
// complements the normal process initiated by calling the GracefulStop method
@@ -107,10 +113,10 @@ func (s *TunnelServiceHandler) InitiateShutdown() {
107
113
s .stopping .Store (true )
108
114
}
109
115
110
- // OpenTunnel creates a forward tunnel from the RPC client to this server. Any
116
+ // openTunnel creates a forward tunnel from the RPC client to this server. Any
111
117
// services registered with this handler will be accessible to RPCs issued over
112
118
// the tunnel.
113
- func (s * TunnelServiceHandler ) OpenTunnel (stream tunnelpb.TunnelService_OpenTunnelServer ) error {
119
+ func (s * TunnelServiceHandler ) openTunnel (stream tunnelpb.TunnelService_OpenTunnelServer ) error {
114
120
if len (s .handlers ) == 0 {
115
121
return status .Error (codes .Unimplemented , "forward tunnels not supported" )
116
122
}
@@ -126,12 +132,12 @@ func (s *TunnelServiceHandler) OpenTunnel(stream tunnelpb.TunnelService_OpenTunn
126
132
return serveTunnel (stream , md , s .handlers , s .stopping .Load )
127
133
}
128
134
129
- // OpenReverseTunnel creates a reverse tunnel from this server to the RPC client.
135
+ // openReverseTunnel creates a reverse tunnel from this server to the RPC client.
130
136
// This handler can be used as an RPC client connection, via AsChannel and
131
137
// KeyAsChannel, to send RPCs to the client on the other end of the reverse
132
138
// tunnel. The RPC client acts as the server and uses NewReverseTunnelServer to
133
139
// create a server and register exposed RPC services with it.
134
- func (s * TunnelServiceHandler ) OpenReverseTunnel (stream tunnelpb.TunnelService_OpenReverseTunnelServer ) error {
140
+ func (s * TunnelServiceHandler ) openReverseTunnel (stream tunnelpb.TunnelService_OpenReverseTunnelServer ) error {
135
141
if s .noReverseTunnels {
136
142
return status .Error (codes .Unimplemented , "reverse tunnels not supported" )
137
143
}
@@ -183,6 +189,19 @@ func (s *TunnelServiceHandler) unregister(ch *tunnelChannel) {
183
189
}
184
190
}
185
191
192
+ type tunnelServiceHandler struct {
193
+ tunnelpb.UnimplementedTunnelServiceServer
194
+ h * TunnelServiceHandler
195
+ }
196
+
197
+ func (s * tunnelServiceHandler ) OpenTunnel (stream tunnelpb.TunnelService_OpenTunnelServer ) error {
198
+ return s .h .openTunnel (stream )
199
+ }
200
+
201
+ func (s * tunnelServiceHandler ) OpenReverseTunnel (stream tunnelpb.TunnelService_OpenReverseTunnelServer ) error {
202
+ return s .h .openReverseTunnel (stream )
203
+ }
204
+
186
205
type reverseChannels struct {
187
206
mu sync.Mutex
188
207
avail chan struct {}
0 commit comments