@@ -19,35 +19,70 @@ package proxy
19
19
import (
20
20
"context"
21
21
"errors"
22
+ "fmt"
22
23
"io"
23
24
25
+ "google.golang.org/grpc"
24
26
"google.golang.org/protobuf/types/known/anypb"
27
+ "google.golang.org/protobuf/types/known/emptypb"
25
28
26
29
transferapi "github.com/containerd/containerd/api/services/transfer/v1"
27
30
transfertypes "github.com/containerd/containerd/api/types/transfer"
28
31
"github.com/containerd/containerd/v2/core/streaming"
29
32
"github.com/containerd/containerd/v2/core/transfer"
30
33
tstreaming "github.com/containerd/containerd/v2/core/transfer/streaming"
31
34
"github.com/containerd/containerd/v2/pkg/oci"
35
+ "github.com/containerd/errdefs"
32
36
"github.com/containerd/log"
37
+ "github.com/containerd/ttrpc"
33
38
"github.com/containerd/typeurl/v2"
34
39
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
35
40
)
36
41
37
42
type proxyTransferrer struct {
38
- client transferapi.TransferClient
43
+ client transferapi.TTRPCTransferService
39
44
streamCreator streaming.StreamCreator
40
45
}
41
46
42
- // NewTransferrer returns a new transferrer which communicates over a GRPC
43
- // connection using the containerd transfer API
44
- func NewTransferrer (client transferapi.TransferClient , sc streaming.StreamCreator ) transfer.Transferrer {
45
- return & proxyTransferrer {
46
- client : client ,
47
- streamCreator : sc ,
47
+ // NewTransferrer returns a new transferrer which can communicate over a GRPC
48
+ // or TTRPC connection using the containerd transfer API
49
+ func NewTransferrer (client any , sc streaming.StreamCreator ) transfer.Transferrer {
50
+ switch c := client .(type ) {
51
+ case transferapi.TransferClient :
52
+ return & proxyTransferrer {
53
+ client : convertClient {c },
54
+ streamCreator : sc ,
55
+ }
56
+ case grpc.ClientConnInterface :
57
+ return & proxyTransferrer {
58
+ client : convertClient {transferapi .NewTransferClient (c )},
59
+ streamCreator : sc ,
60
+ }
61
+ case transferapi.TTRPCTransferService :
62
+ return & proxyTransferrer {
63
+ client : c ,
64
+ streamCreator : sc ,
65
+ }
66
+ case * ttrpc.Client :
67
+ return & proxyTransferrer {
68
+ client : transferapi .NewTTRPCTransferClient (c ),
69
+ streamCreator : sc ,
70
+ }
71
+ case transfer.Transferrer :
72
+ return c
73
+ default :
74
+ panic (fmt .Errorf ("unsupported stream client %T: %w" , client , errdefs .ErrNotImplemented ))
48
75
}
49
76
}
50
77
78
+ type convertClient struct {
79
+ transferapi.TransferClient
80
+ }
81
+
82
+ func (c convertClient ) Transfer (ctx context.Context , r * transferapi.TransferRequest ) (* emptypb.Empty , error ) {
83
+ return c .TransferClient .Transfer (ctx , r )
84
+ }
85
+
51
86
func (p * proxyTransferrer ) Transfer (ctx context.Context , src interface {}, dst interface {}, opts ... transfer.Opt ) error {
52
87
o := & transfer.Config {}
53
88
for _ , opt := range opts {
0 commit comments