MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / handleInbounds

Method handleInbounds

internal/serverapi/inbounds.go:42–93  ·  view source on GitHub ↗

─── Inbound handlers ────────────────────────────────────────────────────────

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

40// ─── Inbound handlers ────────────────────────────────────────────────────────
41
42func (a *inboundAPI) handleInbounds(w http.ResponseWriter, r *http.Request) {
43 switch r.Method {
44 case http.MethodGet:
45 var items []inbounds.Inbound
46 var err error
47 if nodeID := r.URL.Query().Get("node_id"); nodeID != "" {
48 items, err = a.store.ListInboundsByNode(nodeID)
49 } else {
50 items, err = a.store.ListInbounds()
51 }
52 if err != nil {
53 internalError(w, r, err)
54 return
55 }
56 userCounts, err := a.userStore.CountUsersByInbound()
57 if err != nil {
58 internalError(w, r, err)
59 return
60 }
61 writeJSON(w, http.StatusOK, map[string]any{"inbounds": items, "user_counts": userCounts})
62 case http.MethodPost:
63 var req inbounds.Inbound
64 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
65 writeJSON(w, http.StatusBadRequest, map[string]any{"error": "invalid json body"})
66 return
67 }
68 if req.NodeID == "" || req.Protocol == "" || req.Port == 0 {
69 writeJSON(w, http.StatusBadRequest, map[string]any{"error": "node_id, protocol and port are required"})
70 return
71 }
72 if !supportedProtocol(req.Protocol) {
73 writeJSON(w, http.StatusBadRequest, map[string]any{"error": "unsupported protocol"})
74 return
75 }
76 if req.ID == "" {
77 req.ID = idgen.NextString()
78 }
79 if req.Tag == "" {
80 req.Tag = fmt.Sprintf("%s-%d", req.Protocol, req.Port)
81 }
82 trimInbound(&req)
83 item, err := a.store.UpsertInbound(req)
84 if err != nil {
85 internalError(w, r, err)
86 return
87 }
88 a.applyInboundNode(item.NodeID)
89 writeJSON(w, http.StatusOK, item)
90 default:
91 writeMethodNotAllowed(w, http.MethodGet+", "+http.MethodPost)
92 }
93}
94
95func (a *inboundAPI) handleInboundRoutes(w http.ResponseWriter, r *http.Request) {
96 path := strings.TrimPrefix(r.URL.Path, "/v1/inbounds/")

Callers

nothing calls this directly

Calls 13

applyInboundNodeMethod · 0.95
NextStringFunction · 0.92
internalErrorFunction · 0.85
supportedProtocolFunction · 0.85
trimInboundFunction · 0.85
writeMethodNotAllowedFunction · 0.85
writeJSONFunction · 0.70
GetMethod · 0.65
QueryMethod · 0.65
ListInboundsByNodeMethod · 0.65
ListInboundsMethod · 0.65
CountUsersByInboundMethod · 0.65

Tested by

no test coverage detected