2014-10-22 00:02:20 +02:00
|
|
|
package ipc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"reflect"
|
|
|
|
|
2014-11-06 21:16:14 +01:00
|
|
|
"github.com/docker/docker-registry/storagedriver"
|
2014-10-22 00:02:20 +02:00
|
|
|
"github.com/docker/libchan"
|
|
|
|
)
|
|
|
|
|
2014-11-06 21:16:14 +01:00
|
|
|
// IPCStorageDriver is the interface which IPC storage drivers must implement. As external storage
|
|
|
|
// drivers may be defined to use a different version of the storagedriver.StorageDriver interface,
|
|
|
|
// we use an additional version check to determine compatiblity.
|
|
|
|
type IPCStorageDriver interface {
|
|
|
|
// Version returns the storagedriver.StorageDriver interface version which this storage driver
|
|
|
|
// implements, which is used to determine driver compatibility
|
|
|
|
Version() (storagedriver.Version, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IncompatibleVersionError is returned when a storage driver is using an incompatible version of
|
|
|
|
// the storagedriver.StorageDriver api
|
|
|
|
type IncompatibleVersionError struct {
|
|
|
|
version storagedriver.Version
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e IncompatibleVersionError) Error() string {
|
|
|
|
return fmt.Sprintf("Incompatible storage driver version: %s", e.version)
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// Request defines a remote method call request
|
2014-10-29 02:15:40 +01:00
|
|
|
// A return value struct is to be sent over the ResponseChannel
|
2014-10-22 00:02:20 +02:00
|
|
|
type Request struct {
|
|
|
|
Type string
|
|
|
|
Parameters map[string]interface{}
|
|
|
|
ResponseChannel libchan.Sender
|
|
|
|
}
|
|
|
|
|
|
|
|
type responseError struct {
|
|
|
|
Type string
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// ResponseError wraps an error in a serializable struct containing the error's type and message
|
2014-10-22 00:02:20 +02:00
|
|
|
func ResponseError(err error) *responseError {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &responseError{
|
|
|
|
Type: reflect.TypeOf(err).String(),
|
|
|
|
Message: err.Error(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *responseError) Error() string {
|
|
|
|
return fmt.Sprintf("%s: %s", err.Type, err.Message)
|
|
|
|
}
|
|
|
|
|
2014-10-29 02:15:40 +01:00
|
|
|
// IPC method call response object definitions
|
|
|
|
|
2014-11-06 21:16:14 +01:00
|
|
|
// VersionResponse is a response for a Version request
|
|
|
|
type VersionResponse struct {
|
|
|
|
Version storagedriver.Version
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// ReadStreamResponse is a response for a ReadStream request
|
2014-10-22 00:02:20 +02:00
|
|
|
type ReadStreamResponse struct {
|
2014-10-31 19:50:02 +01:00
|
|
|
Reader io.ReadCloser
|
2014-10-22 00:02:20 +02:00
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// WriteStreamResponse is a response for a WriteStream request
|
2014-10-22 00:02:20 +02:00
|
|
|
type WriteStreamResponse struct {
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-11-07 21:58:48 +01:00
|
|
|
// CurrentSizeResponse is a response for a CurrentSize request
|
|
|
|
type CurrentSizeResponse struct {
|
2014-10-22 00:02:20 +02:00
|
|
|
Position uint64
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// ListResponse is a response for a List request
|
2014-10-22 00:02:20 +02:00
|
|
|
type ListResponse struct {
|
|
|
|
Keys []string
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// MoveResponse is a response for a Move request
|
2014-10-22 00:02:20 +02:00
|
|
|
type MoveResponse struct {
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// DeleteResponse is a response for a Delete request
|
2014-10-22 00:02:20 +02:00
|
|
|
type DeleteResponse struct {
|
|
|
|
Error *responseError
|
|
|
|
}
|