api

package module
v0.0.0-...-0cf4ba9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 18 Imported by: 2

Documentation

Overview

Package api is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

This section is empty.

Variables

View Source
var File_torrent_proto protoreflect.FileDescriptor

Functions

func RegisterPeerHandler

func RegisterPeerHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterPeerHandler registers the http handlers for service Peer to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterPeerHandlerClient

func RegisterPeerHandlerClient(ctx context.Context, mux *runtime.ServeMux, client PeerClient) error

RegisterPeerHandlerClient registers the http handlers for service Peer to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "PeerClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "PeerClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "PeerClient" to call the correct interceptors.

func RegisterPeerHandlerFromEndpoint

func RegisterPeerHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterPeerHandlerFromEndpoint is same as RegisterPeerHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterPeerHandlerServer

func RegisterPeerHandlerServer(ctx context.Context, mux *runtime.ServeMux, server PeerServer) error

RegisterPeerHandlerServer registers the http handlers for service Peer to "mux". UnaryRPC :call PeerServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterPeerHandlerFromEndpoint instead.

func RegisterPeerServer

func RegisterPeerServer(s *grpc.Server, srv PeerServer)

func RegisterTrackerHandler

func RegisterTrackerHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterTrackerHandler registers the http handlers for service Tracker to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterTrackerHandlerClient

func RegisterTrackerHandlerClient(ctx context.Context, mux *runtime.ServeMux, client TrackerClient) error

RegisterTrackerHandlerClient registers the http handlers for service Tracker to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "TrackerClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "TrackerClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "TrackerClient" to call the correct interceptors.

func RegisterTrackerHandlerFromEndpoint

func RegisterTrackerHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterTrackerHandlerFromEndpoint is same as RegisterTrackerHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterTrackerHandlerServer

func RegisterTrackerHandlerServer(ctx context.Context, mux *runtime.ServeMux, server TrackerServer) error

RegisterTrackerHandlerServer registers the http handlers for service Tracker to "mux". UnaryRPC :call TrackerServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterTrackerHandlerFromEndpoint instead.

func RegisterTrackerServer

func RegisterTrackerServer(s *grpc.Server, srv TrackerServer)

Types

type DownloadFileRequest

type DownloadFileRequest struct {
	Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
	// contains filtered or unexported fields
}

func (*DownloadFileRequest) Descriptor deprecated

func (*DownloadFileRequest) Descriptor() ([]byte, []int)

Deprecated: Use DownloadFileRequest.ProtoReflect.Descriptor instead.

func (*DownloadFileRequest) GetHash

func (x *DownloadFileRequest) GetHash() string

func (*DownloadFileRequest) ProtoMessage

func (*DownloadFileRequest) ProtoMessage()

func (*DownloadFileRequest) ProtoReflect

func (x *DownloadFileRequest) ProtoReflect() protoreflect.Message

func (*DownloadFileRequest) Reset

func (x *DownloadFileRequest) Reset()

func (*DownloadFileRequest) String

func (x *DownloadFileRequest) String() string

type DownloadFileResponse

type DownloadFileResponse struct {
	FilePath string `protobuf:"bytes,1,opt,name=file_path,json=filePath,proto3" json:"file_path,omitempty"`
	// contains filtered or unexported fields
}

func (*DownloadFileResponse) Descriptor deprecated

func (*DownloadFileResponse) Descriptor() ([]byte, []int)

Deprecated: Use DownloadFileResponse.ProtoReflect.Descriptor instead.

func (*DownloadFileResponse) GetFilePath

func (x *DownloadFileResponse) GetFilePath() string

func (*DownloadFileResponse) ProtoMessage

func (*DownloadFileResponse) ProtoMessage()

func (*DownloadFileResponse) ProtoReflect

func (x *DownloadFileResponse) ProtoReflect() protoreflect.Message

func (*DownloadFileResponse) Reset

func (x *DownloadFileResponse) Reset()

func (*DownloadFileResponse) String

func (x *DownloadFileResponse) String() string

type File

type File struct {
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// contains filtered or unexported fields
}

func (*File) Descriptor deprecated

func (*File) Descriptor() ([]byte, []int)

Deprecated: Use File.ProtoReflect.Descriptor instead.

func (*File) GetName

func (x *File) GetName() string

func (*File) ProtoMessage

func (*File) ProtoMessage()

func (*File) ProtoReflect

func (x *File) ProtoReflect() protoreflect.Message

func (*File) Reset

func (x *File) Reset()

func (*File) String

func (x *File) String() string

type FileInfo

type FileInfo struct {
	Name        string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`                                   // имя файла
	PieceLength uint64 `protobuf:"varint,2,opt,name=piece_length,json=pieceLength,proto3" json:"piece_length,omitempty"` // длина кусочка
	Pieces      uint64 `protobuf:"varint,3,opt,name=pieces,proto3" json:"pieces,omitempty"`                              // всего кусочков
	Length      uint64 `protobuf:"varint,4,opt,name=length,proto3" json:"length,omitempty"`                              // длина файла
	Hash        string `protobuf:"bytes,5,opt,name=hash,proto3" json:"hash,omitempty"`                                   // хэш файла
	// contains filtered or unexported fields
}

func (*FileInfo) Descriptor deprecated

func (*FileInfo) Descriptor() ([]byte, []int)

Deprecated: Use FileInfo.ProtoReflect.Descriptor instead.

func (*FileInfo) GetHash

func (x *FileInfo) GetHash() string

func (*FileInfo) GetLength

func (x *FileInfo) GetLength() uint64

func (*FileInfo) GetName

func (x *FileInfo) GetName() string

func (*FileInfo) GetPieceLength

func (x *FileInfo) GetPieceLength() uint64

func (*FileInfo) GetPieces

func (x *FileInfo) GetPieces() uint64

func (*FileInfo) ProtoMessage

func (*FileInfo) ProtoMessage()

func (*FileInfo) ProtoReflect

func (x *FileInfo) ProtoReflect() protoreflect.Message

func (*FileInfo) Reset

func (x *FileInfo) Reset()

func (*FileInfo) String

func (x *FileInfo) String() string

type GetPeersRequest

type GetPeersRequest struct {
	HashFile string `protobuf:"bytes,1,opt,name=hash_file,json=hashFile,proto3" json:"hash_file,omitempty"` // хэш файла - файл который надо скачать
	PeerId   string `protobuf:"bytes,2,opt,name=peer_id,json=peerId,proto3" json:"peer_id,omitempty"`       // сгенерированный uuid клиента - его пир
	// contains filtered or unexported fields
}

func (*GetPeersRequest) Descriptor deprecated

func (*GetPeersRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetPeersRequest.ProtoReflect.Descriptor instead.

func (*GetPeersRequest) GetHashFile

func (x *GetPeersRequest) GetHashFile() string

func (*GetPeersRequest) GetPeerId

func (x *GetPeersRequest) GetPeerId() string

func (*GetPeersRequest) ProtoMessage

func (*GetPeersRequest) ProtoMessage()

func (*GetPeersRequest) ProtoReflect

func (x *GetPeersRequest) ProtoReflect() protoreflect.Message

func (*GetPeersRequest) Reset

func (x *GetPeersRequest) Reset()

func (*GetPeersRequest) String

func (x *GetPeersRequest) String() string

type GetPieceRequest

type GetPieceRequest struct {
	SerialNumber uint64 `protobuf:"varint,1,opt,name=serial_number,json=serialNumber,proto3" json:"serial_number,omitempty"`
	Hash         string `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
	// contains filtered or unexported fields
}

func (*GetPieceRequest) Descriptor deprecated

func (*GetPieceRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetPieceRequest.ProtoReflect.Descriptor instead.

func (*GetPieceRequest) GetHash

func (x *GetPieceRequest) GetHash() string

func (*GetPieceRequest) GetSerialNumber

func (x *GetPieceRequest) GetSerialNumber() uint64

func (*GetPieceRequest) ProtoMessage

func (*GetPieceRequest) ProtoMessage()

func (*GetPieceRequest) ProtoReflect

func (x *GetPieceRequest) ProtoReflect() protoreflect.Message

func (*GetPieceRequest) Reset

func (x *GetPieceRequest) Reset()

func (*GetPieceRequest) String

func (x *GetPieceRequest) String() string

type ListFiles

type ListFiles struct {
	Count uint64      `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"`
	Files []*FileInfo `protobuf:"bytes,2,rep,name=files,proto3" json:"files,omitempty"`
	// contains filtered or unexported fields
}

func (*ListFiles) Descriptor deprecated

func (*ListFiles) Descriptor() ([]byte, []int)

Deprecated: Use ListFiles.ProtoReflect.Descriptor instead.

func (*ListFiles) GetCount

func (x *ListFiles) GetCount() uint64

func (*ListFiles) GetFiles

func (x *ListFiles) GetFiles() []*FileInfo

func (*ListFiles) ProtoMessage

func (*ListFiles) ProtoMessage()

func (*ListFiles) ProtoReflect

func (x *ListFiles) ProtoReflect() protoreflect.Message

func (*ListFiles) Reset

func (x *ListFiles) Reset()

func (*ListFiles) String

func (x *ListFiles) String() string

type ListPeers

type ListPeers struct {
	Count uint64            `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"`
	Peers []*ListPeers_Peer `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,omitempty"`
	// contains filtered or unexported fields
}

func (*ListPeers) Descriptor deprecated

func (*ListPeers) Descriptor() ([]byte, []int)

Deprecated: Use ListPeers.ProtoReflect.Descriptor instead.

func (*ListPeers) GetCount

func (x *ListPeers) GetCount() uint64

func (*ListPeers) GetPeers

func (x *ListPeers) GetPeers() []*ListPeers_Peer

func (*ListPeers) ProtoMessage

func (*ListPeers) ProtoMessage()

func (*ListPeers) ProtoReflect

func (x *ListPeers) ProtoReflect() protoreflect.Message

func (*ListPeers) Reset

func (x *ListPeers) Reset()

func (*ListPeers) String

func (x *ListPeers) String() string

type ListPeers_Peer

type ListPeers_Peer struct {
	Address      string   `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`                                       // summary address
	SerialPieces []uint64 `protobuf:"varint,2,rep,packed,name=serial_pieces,json=serialPieces,proto3" json:"serial_pieces,omitempty"` // номера доступных кусочков
	// contains filtered or unexported fields
}

func (*ListPeers_Peer) Descriptor deprecated

func (*ListPeers_Peer) Descriptor() ([]byte, []int)

Deprecated: Use ListPeers_Peer.ProtoReflect.Descriptor instead.

func (*ListPeers_Peer) GetAddress

func (x *ListPeers_Peer) GetAddress() string

func (*ListPeers_Peer) GetSerialPieces

func (x *ListPeers_Peer) GetSerialPieces() []uint64

func (*ListPeers_Peer) ProtoMessage

func (*ListPeers_Peer) ProtoMessage()

func (*ListPeers_Peer) ProtoReflect

func (x *ListPeers_Peer) ProtoReflect() protoreflect.Message

func (*ListPeers_Peer) Reset

func (x *ListPeers_Peer) Reset()

func (*ListPeers_Peer) String

func (x *ListPeers_Peer) String() string

type PeerClient

type PeerClient interface {
	GetPiece(ctx context.Context, in *GetPieceRequest, opts ...grpc.CallOption) (*Piece, error)
	UploadFile(ctx context.Context, in *File, opts ...grpc.CallOption) (*empty.Empty, error)
	GetFileInfo(ctx context.Context, in *File, opts ...grpc.CallOption) (*FileInfo, error)
	Download(ctx context.Context, in *DownloadFileRequest, opts ...grpc.CallOption) (*DownloadFileResponse, error)
}

PeerClient is the client API for Peer service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewPeerClient

func NewPeerClient(cc grpc.ClientConnInterface) PeerClient

type PeerServer

type PeerServer interface {
	GetPiece(context.Context, *GetPieceRequest) (*Piece, error)
	UploadFile(context.Context, *File) (*empty.Empty, error)
	GetFileInfo(context.Context, *File) (*FileInfo, error)
	Download(context.Context, *DownloadFileRequest) (*DownloadFileResponse, error)
}

PeerServer is the server API for Peer service.

type Piece

type Piece struct {
	Payload      []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"`                                // кусочек
	SerialNumber uint64 `protobuf:"varint,2,opt,name=serial_number,json=serialNumber,proto3" json:"serial_number,omitempty"` // номер кусочка
	// contains filtered or unexported fields
}

func (*Piece) Descriptor deprecated

func (*Piece) Descriptor() ([]byte, []int)

Deprecated: Use Piece.ProtoReflect.Descriptor instead.

func (*Piece) GetPayload

func (x *Piece) GetPayload() []byte

func (*Piece) GetSerialNumber

func (x *Piece) GetSerialNumber() uint64

func (*Piece) ProtoMessage

func (*Piece) ProtoMessage()

func (*Piece) ProtoReflect

func (x *Piece) ProtoReflect() protoreflect.Message

func (*Piece) Reset

func (x *Piece) Reset()

func (*Piece) String

func (x *Piece) String() string

type PieceInfo

type PieceInfo struct {
	HashFile string `protobuf:"bytes,1,opt,name=hash_file,json=hashFile,proto3" json:"hash_file,omitempty"`
	Serial   uint64 `protobuf:"varint,2,opt,name=serial,proto3" json:"serial,omitempty"` // кусочек который скачан и раздается
	// contains filtered or unexported fields
}

func (*PieceInfo) Descriptor deprecated

func (*PieceInfo) Descriptor() ([]byte, []int)

Deprecated: Use PieceInfo.ProtoReflect.Descriptor instead.

func (*PieceInfo) GetHashFile

func (x *PieceInfo) GetHashFile() string

func (*PieceInfo) GetSerial

func (x *PieceInfo) GetSerial() uint64

func (*PieceInfo) ProtoMessage

func (*PieceInfo) ProtoMessage()

func (*PieceInfo) ProtoReflect

func (x *PieceInfo) ProtoReflect() protoreflect.Message

func (*PieceInfo) Reset

func (x *PieceInfo) Reset()

func (*PieceInfo) String

func (x *PieceInfo) String() string

type TrackerClient

type TrackerClient interface {
	GetAvailableFiles(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ListFiles, error)
	GetFileInfo(ctx context.Context, in *DownloadFileRequest, opts ...grpc.CallOption) (*FileInfo, error)
	Upload(ctx context.Context, in *UploadFileRequest, opts ...grpc.CallOption) (*empty.Empty, error)
	GetPeers(ctx context.Context, in *GetPeersRequest, opts ...grpc.CallOption) (*ListPeers, error)
	PostPieceInfo(ctx context.Context, in *PieceInfo, opts ...grpc.CallOption) (*empty.Empty, error)
}

TrackerClient is the client API for Tracker service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewTrackerClient

func NewTrackerClient(cc grpc.ClientConnInterface) TrackerClient

type TrackerServer

type TrackerServer interface {
	GetAvailableFiles(context.Context, *empty.Empty) (*ListFiles, error)
	GetFileInfo(context.Context, *DownloadFileRequest) (*FileInfo, error)
	Upload(context.Context, *UploadFileRequest) (*empty.Empty, error)
	GetPeers(context.Context, *GetPeersRequest) (*ListPeers, error)
	PostPieceInfo(context.Context, *PieceInfo) (*empty.Empty, error)
}

TrackerServer is the server API for Tracker service.

type UnimplementedPeerServer

type UnimplementedPeerServer struct {
}

UnimplementedPeerServer can be embedded to have forward compatible implementations.

func (*UnimplementedPeerServer) Download

func (*UnimplementedPeerServer) GetFileInfo

func (*UnimplementedPeerServer) GetPiece

func (*UnimplementedPeerServer) UploadFile

type UnimplementedTrackerServer

type UnimplementedTrackerServer struct {
}

UnimplementedTrackerServer can be embedded to have forward compatible implementations.

func (*UnimplementedTrackerServer) GetAvailableFiles

func (*UnimplementedTrackerServer) GetFileInfo

func (*UnimplementedTrackerServer) GetPeers

func (*UnimplementedTrackerServer) PostPieceInfo

func (*UnimplementedTrackerServer) Upload

type UploadFileRequest

type UploadFileRequest struct {
	ClientId    string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
	Name        string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`                                   // имя файла
	PieceLength uint64 `protobuf:"varint,3,opt,name=piece_length,json=pieceLength,proto3" json:"piece_length,omitempty"` // длина кусочка
	Pieces      uint64 `protobuf:"varint,4,opt,name=pieces,proto3" json:"pieces,omitempty"`                              // всего кусочков
	Length      uint64 `protobuf:"varint,5,opt,name=length,proto3" json:"length,omitempty"`                              // длина файла
	Hash        string `protobuf:"bytes,6,opt,name=hash,proto3" json:"hash,omitempty"`                                   // хэш файла
	// contains filtered or unexported fields
}

func (*UploadFileRequest) Descriptor deprecated

func (*UploadFileRequest) Descriptor() ([]byte, []int)

Deprecated: Use UploadFileRequest.ProtoReflect.Descriptor instead.

func (*UploadFileRequest) GetClientId

func (x *UploadFileRequest) GetClientId() string

func (*UploadFileRequest) GetHash

func (x *UploadFileRequest) GetHash() string

func (*UploadFileRequest) GetLength

func (x *UploadFileRequest) GetLength() uint64

func (*UploadFileRequest) GetName

func (x *UploadFileRequest) GetName() string

func (*UploadFileRequest) GetPieceLength

func (x *UploadFileRequest) GetPieceLength() uint64

func (*UploadFileRequest) GetPieces

func (x *UploadFileRequest) GetPieces() uint64

func (*UploadFileRequest) ProtoMessage

func (*UploadFileRequest) ProtoMessage()

func (*UploadFileRequest) ProtoReflect

func (x *UploadFileRequest) ProtoReflect() protoreflect.Message

func (*UploadFileRequest) Reset

func (x *UploadFileRequest) Reset()

func (*UploadFileRequest) String

func (x *UploadFileRequest) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL