-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathtypes.go
More file actions
136 lines (119 loc) · 4.07 KB
/
types.go
File metadata and controls
136 lines (119 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package jsonproxy
import (
"errors"
"fmt"
"os"
"sync"
"syscall"
"github.com/opencontainers/go-digest"
"go.podman.io/common/pkg/retry"
"go.podman.io/image/v5/types"
)
// protocolVersion is semantic version of the protocol used by this proxy.
// The first version of the protocol has major version 0.2 to signify a
// departure from the original code which used HTTP.
//
// When bumping this, please also update the man page.
const protocolVersion = "0.2.9"
// maxMsgSize is the current limit on a packet size.
// Note that all non-metadata (i.e. payload data) is sent over a pipe.
const maxMsgSize = 32 * 1024
// maxJSONFloat is ECMA Number.MAX_SAFE_INTEGER
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
// We hard error if the input JSON numbers we expect to be
// integers are above this.
const maxJSONFloat = float64(uint64(1)<<53 - 1)
// sentinelImageID represents "image not found" on the wire.
const sentinelImageID = 0
// request is the JSON serialization of a function call.
type request struct {
// Method is the name of the function.
Method string `json:"method"`
// Args is the arguments (parsed inside the function).
Args []any `json:"args"`
}
type proxyErrorCode string
const (
// proxyErrPipe means we got EPIPE writing to a pipe owned by the client.
proxyErrPipe proxyErrorCode = "EPIPE"
// proxyErrRetryable can be used by clients to automatically retry operations.
proxyErrRetryable proxyErrorCode = "retryable"
// proxyErrOther represents all other errors.
proxyErrOther proxyErrorCode = "other"
)
// proxyError is serialized over the errfd channel for GetRawBlob.
type proxyError struct {
Code proxyErrorCode `json:"code"`
Message string `json:"message"`
}
// reply is serialized to JSON as the return value from a function call.
type reply struct {
// Success is true if and only if the call succeeded.
Success bool `json:"success"`
// Value is an arbitrary value (or values, as array/map) returned from the call.
Value any `json:"value"`
// PipeID is an index into open pipes, and should be passed to FinishPipe.
PipeID uint32 `json:"pipeid"`
// ErrorCode will be non-empty if error is set (new in 0.2.8).
ErrorCode proxyErrorCode `json:"error_code"`
// Error should be non-empty if Success == false.
Error string `json:"error"`
}
// replyBuf is our internal deserialization of reply plus optional fd.
type replyBuf struct {
// value will be converted to a reply Value.
value any
// fd is the read half of a pipe, passed back to the client for additional data.
fd *os.File
// errfd will be a serialization of error state. This is optional and is currently
// only used by GetRawBlob.
errfd *os.File
// pipeid will be provided to the client as PipeID, an index into our open pipes.
pipeid uint32
}
// activePipe is an open pipe to the client
// that contains an error value.
type activePipe struct {
// w is the write half of the pipe.
w *os.File
// wg is completed when our worker goroutine is done.
wg sync.WaitGroup
// err may be set in our worker goroutine.
err error
}
// openImage is an opened image reference.
type openImage struct {
// id is an opaque integer handle.
id uint64
src types.ImageSource
img types.Image
}
// convertedLayerInfo is the reduced form of the OCI type BlobInfo
// used in the return value of GetLayerInfo.
type convertedLayerInfo struct {
Digest digest.Digest `json:"digest"`
Size int64 `json:"size"`
MediaType string `json:"media_type"`
}
// mapProxyErrorCode turns an error into a known string value.
func mapProxyErrorCode(err error) proxyErrorCode {
switch {
case err == nil:
return ""
case errors.Is(err, syscall.EPIPE):
return proxyErrPipe
case retry.IsErrorRetryable(err):
return proxyErrRetryable
default:
return proxyErrOther
}
}
// newProxyError creates a serializable structure for
// the client containing a mapped error code based
// on the error type, plus its value as a string.
func newProxyError(err error) proxyError {
return proxyError{
Code: mapProxyErrorCode(err),
Message: fmt.Sprintf("%v", err),
}
}