comments in commands.go
This commit is contained in:
parent
6959c7c6db
commit
7e2fcb909f
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/thefeli73/polemos/state"
|
"github.com/thefeli73/polemos/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ExecuteCommand is the interface that wraps the Execute method.
|
||||||
type ExecuteCommand interface {
|
type ExecuteCommand interface {
|
||||||
Execute(netip.AddrPort) error
|
Execute(netip.AddrPort) error
|
||||||
}
|
}
|
||||||
@ -21,14 +22,16 @@ type response struct {
|
|||||||
message string `json:"message"`
|
message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProxyCommandStatus is the command to get the status of a proxy
|
||||||
type ProxyCommandStatus struct {
|
type ProxyCommandStatus struct {
|
||||||
Command CommandStatus `json:"status"`
|
Command CommandStatus `json:"status"`
|
||||||
// signature Signature
|
// signature Signature
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandStatus struct {
|
// CommandStatus is the status of a proxy
|
||||||
}
|
type CommandStatus struct {}
|
||||||
|
|
||||||
|
// Execute is the method that executes the Status command
|
||||||
func (c ProxyCommandStatus) Execute(url netip.AddrPort) error {
|
func (c ProxyCommandStatus) Execute(url netip.AddrPort) error {
|
||||||
data, err := json.Marshal(c)
|
data, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -59,16 +62,19 @@ func (c ProxyCommandStatus) Execute(url netip.AddrPort) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandStatus returns a new CommandStatus
|
||||||
func NewCommandStatus() ProxyCommandStatus {
|
func NewCommandStatus() ProxyCommandStatus {
|
||||||
c := CommandStatus{}
|
c := CommandStatus{}
|
||||||
return ProxyCommandStatus{c}
|
return ProxyCommandStatus{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProxyCommandCreate is the command to create a proxy
|
||||||
type ProxyCommandCreate struct {
|
type ProxyCommandCreate struct {
|
||||||
Command CommandCreate `json:"create"`
|
Command CommandCreate `json:"create"`
|
||||||
// signature Signature
|
// signature Signature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommandCreate is the struct for the "Create" Command and contains all the info the proxy needs to create a tunnel
|
||||||
type CommandCreate struct {
|
type CommandCreate struct {
|
||||||
IncomingPort uint16 `json:"incoming_port"`
|
IncomingPort uint16 `json:"incoming_port"`
|
||||||
DestinationPort uint16 `json:"destination_port"`
|
DestinationPort uint16 `json:"destination_port"`
|
||||||
@ -76,6 +82,7 @@ type CommandCreate struct {
|
|||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute is the method that executes the Create command on a ProxyCommandCreate
|
||||||
func (c ProxyCommandCreate) Execute(url netip.AddrPort) error {
|
func (c ProxyCommandCreate) Execute(url netip.AddrPort) error {
|
||||||
data, err := json.Marshal(c)
|
data, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -106,21 +113,25 @@ func (c ProxyCommandCreate) Execute(url netip.AddrPort) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandCreate returns a new CommandCreate
|
||||||
func NewCommandCreate(iport uint16, oport uint16, oip netip.Addr, id state.CustomUUID) ProxyCommandCreate {
|
func NewCommandCreate(iport uint16, oport uint16, oip netip.Addr, id state.CustomUUID) ProxyCommandCreate {
|
||||||
c := CommandCreate{iport, oport, oip, uuid.UUID.String(uuid.UUID(id))}
|
c := CommandCreate{iport, oport, oip, uuid.UUID.String(uuid.UUID(id))}
|
||||||
return ProxyCommandCreate{c}
|
return ProxyCommandCreate{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProxyCommandModify is the command to modify a proxy
|
||||||
type ProxyCommandModify struct {
|
type ProxyCommandModify struct {
|
||||||
Command CommandModify `json:"modify"`
|
Command CommandModify `json:"modify"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommandModify is the struct for the "Modify" Command and contains all the info the proxy needs to modify a tunnel
|
||||||
type CommandModify struct {
|
type CommandModify struct {
|
||||||
DestinationPort uint16 `json:"destination_port"`
|
DestinationPort uint16 `json:"destination_port"`
|
||||||
DestinationIP netip.Addr `json:"destination_ip"`
|
DestinationIP netip.Addr `json:"destination_ip"`
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute is the method that executes the Modify command on a ProxyCommandModify
|
||||||
func (c ProxyCommandModify) Execute(url netip.AddrPort) error {
|
func (c ProxyCommandModify) Execute(url netip.AddrPort) error {
|
||||||
data, err := json.Marshal(c)
|
data, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -151,19 +162,23 @@ func (c ProxyCommandModify) Execute(url netip.AddrPort) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandModify returns a new CommandModify
|
||||||
func NewCommandModify(oport uint16, oip netip.Addr, id state.CustomUUID) ProxyCommandModify {
|
func NewCommandModify(oport uint16, oip netip.Addr, id state.CustomUUID) ProxyCommandModify {
|
||||||
c := CommandModify{oport, oip, uuid.UUID.String(uuid.UUID(id))}
|
c := CommandModify{oport, oip, uuid.UUID.String(uuid.UUID(id))}
|
||||||
return ProxyCommandModify{c}
|
return ProxyCommandModify{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProxyCommandDelete is the command to delete a proxy
|
||||||
type ProxyCommandDelete struct {
|
type ProxyCommandDelete struct {
|
||||||
Command CommandDelete `json:"delete"`
|
Command CommandDelete `json:"delete"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommandDelete is the struct for the "Delete" Command and contains the id of the tunnel to delete
|
||||||
type CommandDelete struct {
|
type CommandDelete struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute is the method that executes the Delete command on a ProxyCommandDelete
|
||||||
func (c ProxyCommandDelete) Execute(url netip.AddrPort) error {
|
func (c ProxyCommandDelete) Execute(url netip.AddrPort) error {
|
||||||
data, err := json.Marshal(c)
|
data, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -194,6 +209,7 @@ func (c ProxyCommandDelete) Execute(url netip.AddrPort) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandDelete returns a new CommandDelete
|
||||||
func NewCommandDelete(id state.CustomUUID) ProxyCommandDelete {
|
func NewCommandDelete(id state.CustomUUID) ProxyCommandDelete {
|
||||||
c := CommandDelete{uuid.UUID.String(uuid.UUID(id))}
|
c := CommandDelete{uuid.UUID.String(uuid.UUID(id))}
|
||||||
return ProxyCommandDelete{c}
|
return ProxyCommandDelete{c}
|
||||||
|
Loading…
Reference in New Issue
Block a user