19 Commits

Author SHA1 Message Date
fiatjaf
8df7c9d773
NewRelayWithContext() and Close(). 2024-02-19 06:33:49 -03:00
fiatjaf
bbe186494e
replace mutex-guarded maps with xsync/v2 maps. 2023-10-03 08:32:07 -03:00
fiatjaf
8968982b9a
relayer, second attempt, now much better. 2023-08-10 14:32:11 -03:00
fiatjaf
dc594ee32b
migrate to fasthttp/websocket. 2023-06-23 07:10:59 -03:00
Yasuhiro Matsumoto
2771d9b8ba fix(all): use v2 module 2023-05-08 12:49:11 -03:00
fiatjaf
e84f5df1f0
make tests pass on base package. 2023-05-01 20:38:11 -03:00
fiatjaf
a4512da371
reimplement server.Start() 2023-05-01 19:56:37 -03:00
fiatjaf
e3d4655dba
v2 with breaking changes and a simpler API. 2023-05-01 19:21:09 -03:00
alex
627724f702 start: introduce Server type and Shutdown (breaking change)
the main motivation for this change is to be able to run tests.
before this commit, Start, Router and Log operated on global variables,
making automated testing unreasonably hard.

this commit puts all that a server needs in a new Server type,
which also made it possible for a Server.Shutdown - see ShutdownAware
doc comments.

BREAKING CHANGES:
- Relay.OnInitialized takes one argument now, *relayer.Server.
- relayer.Router is now replaced by relayer.Server.Router().
  package users can still hook into the router from OnInitialized
  for custom HTTP routing.
- relayer.Log is gone. apart from another global var, imho this was
  a too opinionated choice for a framework to build a custom relay upon.
  this commit introduces a Logger interface which package users can implement
  for zerolog to make it log like before. see Server.Log for details.

other notable changes: finally added a couple basic tests, for start up
and shutdown. doc comments now explain most of the essentials,
hopefully making it more approachable for newcomers and easier to understand
the relayer package.

the changes in handlers.go are minimal, although git diff goes crazy.
this is because most of the lines are simply shifted indentation back by one
due to go fmt.

before this commit:

    func handleWebsocket(relay Relay) func(http.ResponseWriter, *http.Request)
    func handleNIP11(relay Relay) func(http.ResponseWriter, *http.Request)

after:

    func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request)
    func (s *Server) handleNIP11(w http.ResponseWriter, r *http.Request)
2022-12-24 20:41:02 -03:00
alex
932a9b62a7
start: make http server's listening host/port compatible with IPv6 (#14)
previously, a command like this to listen on IPv6 loopback:

    HOST=::1 PORT=7447 go run ./basic/

would exit immediately because ::1:7447 is an invalid address.

IPv6 addresses contain columns, so a simple host + port concatenation
doesn't work. net.JoinHostPort is a function to do exactly that.
2022-12-24 18:53:05 -03:00
alex
642710fda8 start: propagate init errors
package users can now act accordingly on startup errors, for example
by exiting with a non-zero code. this is useful when running a service,
notifying a supervising process about such failures.

although this is technically a breaking change, most pkg users should be
unaffected since Start and StartConf returned nothing before this commit.
2022-12-24 18:52:06 -03:00
alex
570912e752 start: introduce function-args as alternative to env variable params
the Start function always assumes there are environment variables such
as HOST and PORT on start up. this is not always desirable and
especially makes it hard to run independent tests concurrently.

this commit introduces StartConf, an alternative to Start where the
same settings like host and port are passed in a function argument
instead of the global process environment.
2022-12-22 09:23:05 -03:00
fiatjaf
eee9952fac base58 bad-coding session. 2022-08-12 17:02:40 -03:00
fiatjaf
aa96fa0a21 refactor framework interface, simplify basic and whitelisted, bring expensive on and rewrite it. 2022-07-24 17:41:00 -03:00
fiatjaf
8cc12a6bd9 implement nip-11, relay information document. 2022-07-24 11:35:49 -03:00
fiatjaf
668b625651 match the websocket route before implementations. 2021-12-27 11:05:20 -03:00
fiatjaf
80e643c492 expose Router so servers can inject their own routes. 2021-12-26 20:56:42 -03:00
fiatjaf
d9a6c6a1ad fix forgotten envconfig read. 2021-12-26 20:56:22 -03:00
fiatjaf
ba0d99c131 GetListenerFilters() helper and Injector interface for implementations. 2021-12-26 07:11:54 -03:00