Compare commits
No commits in common. "reimplement-status" and "main" have entirely different histories.
reimplemen
...
main
@ -17,42 +17,31 @@ type response struct {
|
|||||||
message string `json:"message"`
|
message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy owns the interfaces for the pcsdk.
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
signing_key string
|
signing_key string
|
||||||
url netip.AddrPort
|
url netip.AddrPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildProxy creates a proxy struct for the given url to easily interact with that proxy instance (create, edit, delete tunnels etc)
|
func BuildProxy(control netip.AddrPort) Proxy {
|
||||||
func BuildProxy(proxyIP netip.AddrPort) Proxy {
|
return Proxy {"", control}
|
||||||
return Proxy {"", proxyIP}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a tunnel with the given parameters.
|
func (p Proxy) Create(iport uint16, oport uint16, oip netip.Addr, id state.CustomUUID) error {
|
||||||
func (p Proxy) Create(entryPort uint16, servicePort uint16, serviceIP netip.Addr, serviceUUID state.CustomUUID) error {
|
_, err := p.execute(create(iport, oport, oip, id))
|
||||||
_, err := p.execute(create(entryPort, servicePort, serviceIP, serviceUUID))
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify a tunnel with the given parameters.
|
func (p Proxy) Modify(oport uint16, oip netip.Addr, id state.CustomUUID) error {
|
||||||
func (p Proxy) Modify(servicePort uint16, serviceIP netip.Addr, serviceUUID state.CustomUUID) error {
|
_, err := p.execute(modify(oport, oip, id))
|
||||||
_, err := p.execute(modify(servicePort, serviceIP, serviceUUID))
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a tunnel with the given parameters.
|
func (p Proxy) Delete(id state.CustomUUID) error {
|
||||||
func (p Proxy) Delete(serviceUUID state.CustomUUID) error {
|
_, err := p.execute(delete(id))
|
||||||
_, err := p.execute(delete(serviceUUID))
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: status function returning map of tunnels
|
// TODO: status function returning map of tunnels
|
||||||
// Status returns a list of tunnels for the given proxy.
|
|
||||||
func (p Proxy) Status() error {
|
|
||||||
_, err := p.execute(status())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func (p Proxy) execute(c command) (string, error) {
|
func (p Proxy) execute(c command) (string, error) {
|
||||||
data, err := json.Marshal(c)
|
data, err := json.Marshal(c)
|
||||||
@ -61,6 +50,7 @@ func (p Proxy) execute(c command) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestURL := fmt.Sprintf("http://%s:%d/command", p.url.Addr().String(), p.url.Port())
|
requestURL := fmt.Sprintf("http://%s:%d/command", p.url.Addr().String(), p.url.Port())
|
||||||
|
fmt.Println(requestURL)
|
||||||
bodyReader := bytes.NewReader(data)
|
bodyReader := bytes.NewReader(data)
|
||||||
|
|
||||||
res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader)
|
res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader)
|
||||||
@ -83,7 +73,6 @@ type command struct {
|
|||||||
Create *commandCreate `json:"create,omitempty"`
|
Create *commandCreate `json:"create,omitempty"`
|
||||||
Modify *commandModify `json:"modify,omitempty"`
|
Modify *commandModify `json:"modify,omitempty"`
|
||||||
Delete *commandDelete `json:"delete,omitempty"`
|
Delete *commandDelete `json:"delete,omitempty"`
|
||||||
Status *commandStatus `json:"status,omitempty"`
|
|
||||||
Timestamp uint64 `json:"timestamp,omitempty"`
|
Timestamp uint64 `json:"timestamp,omitempty"`
|
||||||
Signature string `json:"signature,omitempty"`
|
Signature string `json:"signature,omitempty"`
|
||||||
}
|
}
|
||||||
@ -92,11 +81,11 @@ type commandCreate struct {
|
|||||||
IncomingPort uint16 `json:"incoming_port"`
|
IncomingPort uint16 `json:"incoming_port"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func create(entryPort uint16, servicePort uint16, serviceIP netip.Addr, serviceUUID state.CustomUUID) command {
|
func create(iport uint16, oport uint16, oip netip.Addr, id state.CustomUUID) command {
|
||||||
cr:= commandCreate{entryPort, servicePort, serviceIP, uuid.UUID.String(uuid.UUID(serviceUUID))}
|
cr:= commandCreate{iport, oport, oip, uuid.UUID.String(uuid.UUID(id))}
|
||||||
c:= command{}
|
c:= command{}
|
||||||
c.Create = &cr
|
c.Create = &cr
|
||||||
return c
|
return c
|
||||||
@ -105,34 +94,23 @@ func create(entryPort uint16, servicePort uint16, serviceIP netip.Addr, serviceU
|
|||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func modify(servicePort uint16, serviceIP netip.Addr, serviceUUID state.CustomUUID) command {
|
func modify(oport uint16, oip netip.Addr, id state.CustomUUID) command {
|
||||||
m:= commandModify{servicePort, serviceIP, uuid.UUID.String(uuid.UUID(serviceUUID))}
|
m:= commandModify{oport, oip, uuid.UUID.String(uuid.UUID(id))}
|
||||||
c:= command{}
|
c:= command{}
|
||||||
c.Modify = &m
|
c.Modify = &m
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
type commandDelete struct {
|
type commandDelete struct {
|
||||||
ID string `json:"id"`
|
Id string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete(serviceUUID state.CustomUUID) command {
|
func delete(id state.CustomUUID) command {
|
||||||
d:= commandDelete{uuid.UUID.String(uuid.UUID(serviceUUID))}
|
d:= commandDelete{uuid.UUID.String(uuid.UUID(id))}
|
||||||
c:= command{}
|
c:= command{}
|
||||||
c.Delete = &d
|
c.Delete = &d
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type commandStatus struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func status() command {
|
|
||||||
d:= commandStatus{}
|
|
||||||
c:= command{}
|
|
||||||
c.Status = &d
|
|
||||||
return c
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user