Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions api/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
"github.com/anywherelan/awl/entity"
)

// @Tags Debug
// @Summary Get p2p debug info
// @Produce json
// @Success 200 {object} entity.P2pDebugInfo
// @Router /debug/p2p_info [GET]
// @Tags Debug
// @Summary Get p2p debug info
// @Produce json
// @Success 200 {object} entity.P2pDebugInfo
// @Router /debug/p2p_info [GET]
func (h *Handler) GetP2pDebugInfo(c echo.Context) (err error) {
metricsByProtocol := h.p2p.NetworkStatsByProtocol()
bandwidthByProtocol := make(map[string]entity.BandwidthInfo, len(metricsByProtocol))
Expand Down Expand Up @@ -62,13 +62,13 @@ func (h *Handler) GetP2pDebugInfo(c echo.Context) (err error) {
return c.JSONPretty(http.StatusOK, debugInfo, " ")
}

// @Tags Debug
// @Summary Get logs
// @Param logs query int false "Define number of rows of logs to output. On default and 0 prints all."
// @Param from_head query bool false "Print logs from the beginning of logs"
// @Produce plain
// @Success 200 {string} string "log text"
// @Router /debug/log [GET]
// @Tags Debug
// @Summary Get logs
// @Param logs query int false "Define number of rows of logs to output. On default and 0 prints all."
// @Param from_head query bool false "Print logs from the beginning of logs"
// @Produce plain
// @Success 200 {string} string "log text"
// @Router /debug/log [GET]
func (h *Handler) GetLog(c echo.Context) (err error) {
req := entity.LogRequest{}
err = c.Bind(&req)
Expand Down
126 changes: 63 additions & 63 deletions api/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (

const ErrorPeerAliasIsNotUniq = "peer name is not unique"

// @Tags Peers
// @Summary Get known peers info
// @Accept json
// @Produce json
// @Success 200 {array} entity.KnownPeersResponse
// @Router /peers/get_known [GET]
// @Tags Peers
// @Summary Get known peers info
// @Accept json
// @Produce json
// @Success 200 {array} entity.KnownPeersResponse
// @Router /peers/get_known [GET]
func (h *Handler) GetKnownPeers(c echo.Context) (err error) {
result := h.getKnownPeers()
return c.JSON(http.StatusOK, result)
Expand Down Expand Up @@ -71,15 +71,15 @@ func (h *Handler) getKnownPeers() []entity.KnownPeersResponse {
return result
}

// @Tags Peers
// @Summary Get known peer settings
// @Accept json
// @Produce json
// @Param body body entity.PeerIDRequest true "Params"
// @Success 200 {object} config.KnownPeer
// @Failure 400 {object} api.Error
// @Failure 404 {object} api.Error
// @Router /peers/get_known_peer_settings [POST]
// @Tags Peers
// @Summary Get known peer settings
// @Accept json
// @Produce json
// @Param body body entity.PeerIDRequest true "Params"
// @Success 200 {object} config.KnownPeer
// @Failure 400 {object} api.Error
// @Failure 404 {object} api.Error
// @Router /peers/get_known_peer_settings [POST]
func (h *Handler) GetKnownPeerSettings(c echo.Context) (err error) {
req := entity.PeerIDRequest{}
err = c.Bind(&req)
Expand All @@ -97,15 +97,15 @@ func (h *Handler) GetKnownPeerSettings(c echo.Context) (err error) {
return c.JSON(http.StatusOK, knownPeer)
}

// @Tags Peers
// @Summary Update peer settings
// @Accept json
// @Produce json
// @Param body body entity.UpdatePeerSettingsRequest true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 404 {object} api.Error
// @Router /peers/update_settings [POST]
// @Tags Peers
// @Summary Update peer settings
// @Accept json
// @Produce json
// @Param body body entity.UpdatePeerSettingsRequest true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 404 {object} api.Error
// @Router /peers/update_settings [POST]
func (h *Handler) UpdatePeerSettings(c echo.Context) (err error) {
req := entity.UpdatePeerSettingsRequest{}
err = c.Bind(&req)
Expand Down Expand Up @@ -151,15 +151,15 @@ func (h *Handler) UpdatePeerSettings(c echo.Context) (err error) {
return c.NoContent(http.StatusOK)
}

// @Tags Peers
// @Summary Invite new peer
// @Accept json
// @Produce json
// @Param body body entity.FriendRequest true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 500 {object} api.Error
// @Router /peers/invite_peer [POST]
// @Tags Peers
// @Summary Invite new peer
// @Accept json
// @Produce json
// @Param body body entity.FriendRequest true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 500 {object} api.Error
// @Router /peers/invite_peer [POST]
func (h *Handler) SendFriendRequest(c echo.Context) (err error) {
req := entity.FriendRequest{}
err = c.Bind(&req)
Expand Down Expand Up @@ -188,15 +188,15 @@ func (h *Handler) SendFriendRequest(c echo.Context) (err error) {
return c.NoContent(http.StatusOK)
}

// @Tags Peers
// @Summary Accept new peer's invitation
// @Accept json
// @Produce json
// @Param body body entity.FriendRequestReply true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 500 {object} api.Error
// @Router /peers/accept_peer [POST]
// @Tags Peers
// @Summary Accept new peer's invitation
// @Accept json
// @Produce json
// @Param body body entity.FriendRequestReply true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 500 {object} api.Error
// @Router /peers/accept_peer [POST]
func (h *Handler) AcceptFriend(c echo.Context) (err error) {
req := entity.FriendRequestReply{}
err = c.Bind(&req)
Expand Down Expand Up @@ -236,12 +236,12 @@ func (h *Handler) AcceptFriend(c echo.Context) (err error) {
return c.NoContent(http.StatusOK)
}

// @Tags Peers
// @Summary Get ingoing auth requests
// @Accept json
// @Produce json
// @Success 200 {array} entity.AuthRequest
// @Router /peers/auth_requests [GET]
// @Tags Peers
// @Summary Get ingoing auth requests
// @Accept json
// @Produce json
// @Success 200 {array} entity.AuthRequest
// @Router /peers/auth_requests [GET]
func (h *Handler) GetAuthRequests(c echo.Context) (err error) {
authRequestsMap := h.authStatus.GetIngoingAuthRequests()
authRequests := make([]entity.AuthRequest, 0, len(authRequestsMap))
Expand Down Expand Up @@ -271,15 +271,15 @@ func (h *Handler) GetAuthRequests(c echo.Context) (err error) {
return c.JSON(http.StatusOK, authRequests)
}

// @Tags Peers
// @Summary Remove known peer
// @Accept json
// @Produce json
// @Param body body entity.PeerIDRequest true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 404 {object} api.Error
// @Router /peers/remove [POST]
// @Tags Peers
// @Summary Remove known peer
// @Accept json
// @Produce json
// @Param body body entity.PeerIDRequest true "Params"
// @Success 200 "OK"
// @Failure 400 {object} api.Error
// @Failure 404 {object} api.Error
// @Router /peers/remove [POST]
func (h *Handler) RemovePeer(c echo.Context) (err error) {
req := entity.PeerIDRequest{}
err = c.Bind(&req)
Expand All @@ -306,12 +306,12 @@ func (h *Handler) RemovePeer(c echo.Context) (err error) {
return c.NoContent(http.StatusOK)
}

// @Tags Peers
// @Summary Get blocked peers info
// @Accept json
// @Produce json
// @Success 200 {array} config.BlockedPeer
// @Router /peers/get_blocked [GET]
// @Tags Peers
// @Summary Get blocked peers info
// @Accept json
// @Produce json
// @Success 200 {array} config.BlockedPeer
// @Router /peers/get_blocked [GET]
func (h *Handler) GetBlockedPeers(c echo.Context) (err error) {
h.conf.RLock()
result := make([]config.BlockedPeer, 0, len(h.conf.BlockedPeers))
Expand Down
64 changes: 32 additions & 32 deletions api/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/anywherelan/awl/entity"
)

// @Tags Settings
// @Summary Get my peer info
// @Accept json
// @Produce json
// @Success 200 {object} entity.PeerInfo
// @Router /settings/peer_info [GET]
// @Tags Settings
// @Summary Get my peer info
// @Accept json
// @Produce json
// @Success 200 {object} entity.PeerInfo
// @Router /settings/peer_info [GET]
func (h *Handler) GetMyPeerInfo(c echo.Context) (err error) {
totalBootstraps, connectedBootstraps := h.p2p.BootstrapPeersStats()
netStats := h.p2p.NetworkStats()
Expand Down Expand Up @@ -51,13 +51,13 @@ func (h *Handler) GetMyPeerInfo(c echo.Context) (err error) {
return c.JSON(http.StatusOK, peerInfo)
}

// @Tags Settings
// @Summary Update my peer info
// @Accept json
// @Produce json
// @Param body body entity.UpdateMySettingsRequest true "Params"
// @Success 200 "OK"
// @Router /settings/update [POST]
// @Tags Settings
// @Summary Update my peer info
// @Accept json
// @Produce json
// @Param body body entity.UpdateMySettingsRequest true "Params"
// @Success 200 "OK"
// @Router /settings/update [POST]
func (h *Handler) UpdateMySettings(c echo.Context) (err error) {
req := entity.UpdateMySettingsRequest{}
err = c.Bind(&req)
Expand All @@ -80,24 +80,24 @@ func (h *Handler) UpdateMySettings(c echo.Context) (err error) {
return c.NoContent(http.StatusOK)
}

// @Tags Settings
// @Summary Export server configuration
// @Accept json
// @Produce json
// @Success 200 {object} config.Config
// @Router /settings/export_server_config [GET]
// @Tags Settings
// @Summary Export server configuration
// @Accept json
// @Produce json
// @Success 200 {object} config.Config
// @Router /settings/export_server_config [GET]
func (h *Handler) ExportServerConfiguration(c echo.Context) (err error) {
data := h.conf.Export()

return c.Blob(http.StatusOK, echo.MIMEApplicationJSON, data)
}

// @Tags Settings
// @Summary List available socks5 proxies
// @Accept json
// @Produce json
// @Success 200 {object} entity.ListAvailableProxiesResponse
// @Router /settings/list_proxies [GET]
// @Tags Settings
// @Summary List available socks5 proxies
// @Accept json
// @Produce json
// @Success 200 {object} entity.ListAvailableProxiesResponse
// @Router /settings/list_proxies [GET]
func (h *Handler) ListAvailableProxies(c echo.Context) (err error) {
proxies := h.socks5.ListAvailableProxies()

Expand All @@ -108,13 +108,13 @@ func (h *Handler) ListAvailableProxies(c echo.Context) (err error) {
return c.JSON(http.StatusOK, response)
}

// @Tags Settings
// @Summary Update current proxy settings
// @Accept json
// @Produce json
// @Param body body entity.UpdateProxySettingsRequest true "Params"
// @Success 200 "OK"
// @Router /settings/set_proxy [POST]
// @Tags Settings
// @Summary Update current proxy settings
// @Accept json
// @Produce json
// @Param body body entity.UpdateProxySettingsRequest true "Params"
// @Success 200 "OK"
// @Router /settings/set_proxy [POST]
func (h *Handler) UpdateProxySettings(c echo.Context) (err error) {
req := entity.UpdateProxySettingsRequest{}
err = c.Bind(&req)
Expand Down
12 changes: 6 additions & 6 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ func FrontendStatic() fs.FS {
return fsys
}

// @title Anywherelan API
// @version 0.1
// @description Anywherelan API
// @title Anywherelan API
// @version 0.1
// @description Anywherelan API

// @Host localhost:8639
// @BasePath /api/v0/
// @Host localhost:8639
// @BasePath /api/v0/

//go:generate swag init --parseDependency -g application.go
//go:generate go run github.com/swaggo/swag/cmd/swag@latest init --parseDependency -g application.go
//go:generate rm -f docs/docs.go docs/swagger.json

type Application struct {
Expand Down
Loading
Loading