good morning!!!!

Skip to content
Snippets Groups Projects
readme.md 4.81 KiB
Newer Older
a's avatar
a committed
## jrpc

a's avatar
a committed
```go get gfx.cafe/open/jrpc```

a's avatar
a committed
this is a bottom up implementation of jsonrpc2, primarily made for hosting eth-like jsonrpc requests.
a's avatar
a committed

a's avatar
a committed
we extend the eth-rpc reflect based handler with go-http style request/response.

we also make things like subscriptions additional extensions, so they are no longer baked into the rpc package.

most users should mostly access the `jrpc` packages, along with a variety of things in `contrib`

see examples in `examples` folder for usage

it is currently being used in the oku.trade api in proxy, client, and server applications.
a's avatar
a committed

a's avatar
a committed
## features
a's avatar
a committed

a's avatar
a committed
 - full jsonrpc2 protocol
 - batch requests + notifications
 - http.Request/http.ResponseWriter style semantics
 - simple but powerful middleware framework
 - subscription framework used by go-ethereum/rpc is implemented as middleware.
 - http (with rest-like access via RPC verb), websocket, io.Reader/io.Writer (tcp, any net.Conn, etc), inproc codecs.
a's avatar
a committed
 - using faster json packages (jsoniter, jx)
a's avatar
a committed
 - extensions, which allow setting arbitrary fields on the parent object, like in sourcegraph jsonrpc2
 - jmux, which allows for http-like routing, implemented like `go-chi/v5`, except for jsonrpc2 paths
 - argreflect, which allows mounting methods on structs to the rpc engine, like go-ethereum/rpc
a's avatar
a committed
 - allows for streaming over eventsource - means subscriptions without websockets
a's avatar
a committed


a's avatar
a committed
## batch requests

batch requests are very weird. the jsonrpc spec indicates that all batch responses must be returned at the same time,
this means for maximum throughput, the user should never use batch requests.

browsers should prefer to use websocket, as it is far more performance than HTTP with batching. websocket frame sizes can also make things such as latency just as good as batching

batch requests are evaulated in a single threaded manner, the next request in the batch blocking until "Send" has been called on the handler.

as a result, batch requests are not very useful.

so to jrpc, we added a new "feature", which is that batch requests are executed sequentially (however in different goroutines).

this is a feature that jsonrpc2 does not have, for jsonrpc2 allows any amount of concurrency and evaluation order for batch requests.


a's avatar
a committed
## maybe outdated but somewhat useful contribution info
a's avatar
a committed

a's avatar
a committed
basic structure
a's avatar
a committed

a's avatar
a committed
```
a's avatar
a committed
exports.go       - export things in subpackages to jrpc namespace, cleaning up the public use package.
a's avatar
a committed
pkg/             - packages for implementing jrpc
  clientutil/      - common utilities for client implementations to use
    idreply.go       - generalizes making a request with an incrementing id, then waiting on it
    helper.go        - helpers for decoding messages, etc
a's avatar
a committed
  jsonrpc/           - jsonrpc related things. to implement new codecs, use this package
a's avatar
a committed
    errors.go        - jsonrpc2 error codes and marshaling
    json.go          - jsonrpc2 json rules, encoding, decoding
    peer.go          - peerinfo
    transport.go     - define ReaderWriter interface
    wire.go          - jsonrpc2 wire protocol marshaling, like ID and Version
    jrpc.go          - define the Handler, HandlerFunc, and ResponseWriter
    reqresp.go       - define Request, Response, along with json marshaling for the request
a's avatar
ok  
a committed
  server/            - server implementation
    server.go        - a simple server implementation that uses a codec.ReaderWriter
a's avatar
a committed
  jrpctest/        - utilities for testing client and server.
    suite.go         - implementors of client and server should pass this
contrib/         - packages that add to jrpc
a's avatar
ok  
a committed
  codecs/          - client and server transport implementations
    codecs.go        - dialers for all finished codecs
    http/              - http based codec
Garet Halliday's avatar
Garet Halliday committed
      codec_test.go      - general tests that all must pass
      client.go          - codec.Conn implementation
      codec.go           - codec.ReaderWriter implementaiton
      const.go           - constants
      handler.go         - http handler
      http_test.go       - http specific tests
    websocket/         - websocket basec codec
      codec_test.go      - general tests that all must pass
      client.go          - codec.Conn implementation
      codec.go           - codec.ReadWriter implementation
      const.go           - constants
      dial.go            - websocket dialer
      handler.go         - http handler
      websocket_test.go  - websocket specific tests
a's avatar
a committed
    rdwr/              - rdwr based codec. can be used to implement other codecs
    inproc/            - inproc based codec
a's avatar
a committed
  openrpc/         - openapi specification implementation
a's avatar
a committed
  jmux/            - a chi based router which satisfies the jrpc.Handler interface
  handlers/        - special jrpc handlers
    argreflect/      - go-ethereum style struct reflection
a's avatar
a committed
  middleware/      - pre implemented middleware
a's avatar
a committed
  extension/       - extensions to the protocol
a's avatar
a committed
    subscription/    - subscription engine for go-ethereum style subs
a's avatar
a committed

a's avatar
a committed
```
a's avatar
a committed