api

package
v1.10.4-0...-52d5685 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Endpoint = "https://api.pwnagotchi.ai/api/v1"
)

Variables

View Source
var (
	ErrTokenClaims       = errors.New("can't extract claims from jwt token")
	ErrTokenInvalid      = errors.New("jwt token not valid")
	ErrTokenExpired      = errors.New("jwt token expired")
	ErrTokenIncomplete   = errors.New("jwt token is missing required fields")
	ErrTokenUnauthorized = errors.New("jwt token authorized field is false (?!)")
)
View Source
var (
	ClientTimeout   = 60
	ClientTokenFile = "/tmp/pwngrid-api-enrollment.json"
)
View Source
var (
	ErrEmptyMessage   = errors.New("empty message body")
	ErrSenderNotFound = errors.New("sender not found")
)
View Source
var (
	ErrRecNotFound      = errors.New("recipient not found")
	ErrMessageNotFound  = errors.New("message not found")
	ErrInvalidKey       = errors.New("invalid public key")
	ErrInvalidSignature = errors.New("can't verify signature")
	ErrDecoding         = errors.New("error decoding data")
)
View Source
var (
	ErrEmpty        = errors.New("")
	ErrUnauthorized = errors.New("unauthorized")
)

Functions

func Authenticate

func Authenticate(w http.ResponseWriter, r *http.Request) *models.Unit

func CORS

func CORS(next http.Handler) http.Handler

func ERROR

func ERROR(w http.ResponseWriter, statusCode int, err error)

func JSON

func JSON(w http.ResponseWriter, statusCode int, data interface{})

Types

type API

type API struct {
	Router *chi.Mux
	Keys   *crypto.KeyPair
	Peer   *mesh.Peer
	Mesh   *mesh.Router
	Client *Client
}

func Setup

func Setup(keys *crypto.KeyPair, peer *mesh.Peer, router *mesh.Router) (err error, api *API)

func (*API) GetInbox

func (api *API) GetInbox(w http.ResponseWriter, r *http.Request)

func (*API) GetInboxMessage

func (api *API) GetInboxMessage(w http.ResponseWriter, r *http.Request)

func (*API) InboxMessage

func (api *API) InboxMessage(id int) (map[string]interface{}, int, error)

func (*API) ListUnits

func (api *API) ListUnits(w http.ResponseWriter, r *http.Request)

func (*API) MarkInboxMessage

func (api *API) MarkInboxMessage(w http.ResponseWriter, r *http.Request)

func (*API) PeerGetData

func (api *API) PeerGetData(w http.ResponseWriter, r *http.Request)

GET /api/v1/data

func (*API) PeerGetInbox

func (api *API) PeerGetInbox(w http.ResponseWriter, r *http.Request)

/api/v1/inbox/

func (*API) PeerGetInboxMessage

func (api *API) PeerGetInboxMessage(w http.ResponseWriter, r *http.Request)

/api/v1/inbox/<msg_id>

func (*API) PeerGetMemory

func (api *API) PeerGetMemory(w http.ResponseWriter, r *http.Request)

GET /api/v1/mesh/memory

func (*API) PeerGetMemoryOf

func (api *API) PeerGetMemoryOf(w http.ResponseWriter, r *http.Request)

GET /api/v1/mesh/memory/<fingerprint>

func (*API) PeerGetMeshData

func (api *API) PeerGetMeshData(w http.ResponseWriter, r *http.Request)

GET /api/v1/mesh/data

func (*API) PeerGetPeers

func (api *API) PeerGetPeers(w http.ResponseWriter, r *http.Request)

GET /api/v1/mesh/peers

func (*API) PeerListUnits

func (api *API) PeerListUnits(w http.ResponseWriter, r *http.Request)

func (*API) PeerMarkInboxMessage

func (api *API) PeerMarkInboxMessage(w http.ResponseWriter, r *http.Request)

/api/v1/inbox/<msg_id>/<mark>

func (*API) PeerReportAP

func (api *API) PeerReportAP(w http.ResponseWriter, r *http.Request)

POST /api/v1/report/ap

func (*API) PeerSendMessageTo

func (api *API) PeerSendMessageTo(w http.ResponseWriter, r *http.Request)

POST /api/v1/unit/<fingerprint>/inbox

func (*API) PeerSetData

func (api *API) PeerSetData(w http.ResponseWriter, r *http.Request)

POST /api/v1/data

func (*API) PeerSetMeshData

func (api *API) PeerSetMeshData(w http.ResponseWriter, r *http.Request)

POST /api/v1/mesh/data

func (*API) PeerSetSignaling

func (api *API) PeerSetSignaling(w http.ResponseWriter, r *http.Request)

GET /api/v1/mesh/<status>

func (*API) Run

func (api *API) Run(addr string)

func (*API) SendMessage

func (api *API) SendMessage(fingerprint string, cleartext []byte) (int, error)

func (*API) SendMessageTo

func (api *API) SendMessageTo(w http.ResponseWriter, r *http.Request)

func (*API) ShowUnit

func (api *API) ShowUnit(w http.ResponseWriter, r *http.Request)

func (*API) UnitEnroll

func (api *API) UnitEnroll(w http.ResponseWriter, r *http.Request)

func (*API) UnitReportAP

func (api *API) UnitReportAP(w http.ResponseWriter, r *http.Request)

func (*API) UnitReportMultipleAP

func (api *API) UnitReportMultipleAP(w http.ResponseWriter, r *http.Request)

func (*API) UnitsByCountry

func (api *API) UnitsByCountry(w http.ResponseWriter, r *http.Request)

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(keys *crypto.KeyPair) *Client

func (*Client) Data

func (c *Client) Data() map[string]interface{}

func (*Client) Get

func (c *Client) Get(path string, auth bool) (map[string]interface{}, error)

func (*Client) Inbox

func (c *Client) Inbox(page int) (map[string]interface{}, error)

func (*Client) InboxMessage

func (c *Client) InboxMessage(id int) (map[string]interface{}, error)

func (*Client) MarkInboxMessage

func (c *Client) MarkInboxMessage(id int, mark string) (map[string]interface{}, error)

func (*Client) PagedUnits

func (c *Client) PagedUnits(page int) (map[string]interface{}, error)

func (*Client) Post

func (c *Client) Post(path string, what interface{}, auth bool) (map[string]interface{}, error)

func (*Client) ReportAP

func (c *Client) ReportAP(report interface{}) (map[string]interface{}, error)

func (*Client) Request

func (c *Client) Request(method string, path string, data interface{}, auth bool) (map[string]interface{}, error)

func (*Client) SendMessageTo

func (c *Client) SendMessageTo(fingerprint string, msg Message) error

func (*Client) SetData

func (c *Client) SetData(newData map[string]interface{}) map[string]interface{}

func (*Client) Unit

func (c *Client) Unit(fingerprint string) (map[string]interface{}, error)

type Message

type Message struct {
	Data      string `json:"data"`
	Signature string `json:"signature"`
}

Jump to

Keyboard shortcuts

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