Files
realy/bunker/main.go
mleku bbebbe2b02 Add tracing with lol.Tracer in multiple functions.
Introduced `lol.Tracer` for function entry/exit logging across various packages. This improves traceability and debugging of function executions while preserving existing behavior. Removed unused files `doc.go` and `nothing.go` to clean up the repository.
2025-06-29 07:32:24 +01:00

77 lines
1.3 KiB
Go

package bunker
import (
"encoding/json"
"net/url"
"strings"
"realy.lol/chk"
"realy.lol/context"
"realy.lol/event"
"realy.lol/keys"
"realy.lol/lol"
)
type Request struct {
ID string `json:"id"`
Method string `json:"method"`
Params [][]byte `json:"params"`
}
func (r *Request) String() (s string) {
lol.Tracer("String")
defer func() { lol.Tracer("end String", s) }()
var j []byte
var err error
if j, err = json.Marshal(r); chk.E(err) {
return
}
s = string(j)
return
}
type Response struct {
ID string `json:"id"`
Error string `json:"error,omitempty"`
Result string `json:"result,omitempty"`
}
func (r *Response) String() (s string) {
var j []byte
var err error
if j, err = json.Marshal(r); chk.E(err) {
return
}
return string(j)
}
type Signer interface {
GetSession(clientPubkey string) (*Session, bool)
HandleRequest(context.T, *event.T) (req *Request, resp *Response,
eventResponse *event.T, err error)
}
type RelayReadWrite struct {
Read, Write bool
}
func IsValidBunkerURL(input string) (is bool) {
lol.Tracer("IsValidBunkerURL", input)
defer func() { lol.Tracer("end IsValidBunkerURL", is) }()
p, err := url.Parse(input)
if err != nil {
return
}
if p.Scheme != "bunker" {
return
}
if !keys.IsValidPublicKey(p.Host) {
return
}
if !strings.Contains(p.RawQuery, "relay=") {
return
}
is = true
return
}