diff --git a/go.work b/go.work index 0689970..582060a 100644 --- a/go.work +++ b/go.work @@ -1,4 +1,6 @@ -go 1.19 +go 1.21 + +toolchain go1.21.3 use ( ./nodemux diff --git a/go.work.sum b/go.work.sum index 63637ed..bcba096 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,4 +1,6 @@ github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/superisaac/jlib v0.4.2/go.mod h1:mr1uMAKhYPhxvtdKGLksNuVEWzd4WhbT+Z/VW8CVcd8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= diff --git a/nodemux/chains/bitcoin.go b/nodemux/chains/bitcoin.go index 4b182fd..7b6027f 100644 --- a/nodemux/chains/bitcoin.go +++ b/nodemux/chains/bitcoin.go @@ -5,7 +5,7 @@ package chains import ( "context" "fmt" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" "time" @@ -37,7 +37,7 @@ func NewBitcoinChain() *BitcoinChain { } func (self BitcoinChain) GetClientVersion(ctx context.Context, ep *nodemuxcore.Endpoint) (string, error) { - reqmsg := jlib.NewRequestMessage(1, "getnetworkinfo", nil) + reqmsg := jsoff.NewRequestMessage(1, "getnetworkinfo", nil) var info bitcoinNetworkInfo err := ep.UnwrapCallRPC(ctx, reqmsg, &info) if err != nil { @@ -57,7 +57,7 @@ func (self BitcoinChain) updateMempoolPresenceCache(ctx context.Context, m *node if !ok { return } - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "getrawmempool", nil) var txids []string @@ -79,7 +79,7 @@ func (self BitcoinChain) updateBlockPresenceCache(ctx context.Context, m *nodemu if !ok { return } - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "getblock", []interface{}{blockHash}) var blk bitcoinBlock @@ -97,7 +97,7 @@ func (self BitcoinChain) updateBlockPresenceCache(ctx context.Context, m *nodemu } func (self *BitcoinChain) GetBlockhead(ctx context.Context, m *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "getblockchaininfo", nil) var chainInfo bitcoinBlockchainInfo @@ -113,7 +113,7 @@ func (self *BitcoinChain) GetBlockhead(ctx context.Context, m *nodemuxcore.Multi return block, nil } -func (self *BitcoinChain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *BitcoinChain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { //useCache := reqmsg.Method == "gettransaction" || reqmsg.Method == "getrawtransaction" || reqmsg.Method == "decoderawtransaction" useCache, resmsgFromCache := jsonrpcCacheFetchForMethods( ctx, m, chain, reqmsg, @@ -131,7 +131,7 @@ func (self *BitcoinChain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multip "getrawtransaction"); ok { retmsg, err := ep.CallRPC(ctx, reqmsg) if err == nil && useCache && retmsg.IsResult() { - jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jlib.ResultMessage), time.Minute*10) + jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jsoff.ResultMessage), time.Minute*10) } return retmsg, err } @@ -147,17 +147,17 @@ func (self *BitcoinChain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multip retmsg, err := m.DefaultRelayRPC(ctx, chain, reqmsg, -1) if err == nil && useCache && retmsg.IsResult() { - jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jlib.ResultMessage), time.Minute*10) + jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jsoff.ResultMessage), time.Minute*10) } return retmsg, nil } -func (self *BitcoinChain) findBlockHeight(reqmsg *jlib.RequestMessage) (int, bool) { +func (self *BitcoinChain) findBlockHeight(reqmsg *jsoff.RequestMessage) (int, bool) { // the first argument is a integer number var bh struct { Height int } - if err := jlib.DecodeParams(reqmsg.Params, &bh); err == nil && bh.Height > 0 { + if err := jsoff.DecodeParams(reqmsg.Params, &bh); err == nil && bh.Height > 0 { return bh.Height, true } return 0, false diff --git a/nodemux/chains/casper.go b/nodemux/chains/casper.go index 3541ff1..b0bf2b0 100644 --- a/nodemux/chains/casper.go +++ b/nodemux/chains/casper.go @@ -4,7 +4,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -32,7 +32,7 @@ func (self CasperChain) StartSync(context context.Context, m *nodemuxcore.Multip } func (self *CasperChain) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "chain_get_block", nil) var bt casperBlock @@ -48,7 +48,7 @@ func (self *CasperChain) GetBlockhead(context context.Context, b *nodemuxcore.Mu return block, nil } -func (self *CasperChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *CasperChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -3) } diff --git a/nodemux/chains/conflux.go b/nodemux/chains/conflux.go index 8b90389..e50da97 100644 --- a/nodemux/chains/conflux.go +++ b/nodemux/chains/conflux.go @@ -2,7 +2,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -23,7 +23,7 @@ func (self ConfluxChain) StartSync(context context.Context, m *nodemuxcore.Multi } func (self *ConfluxChain) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "cfx_epochNumber", []interface{}{"latest_mined"}) var height int @@ -38,7 +38,7 @@ func (self *ConfluxChain) GetBlockhead(context context.Context, b *nodemuxcore.M return block, nil } -func (self *ConfluxChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *ConfluxChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -5) } diff --git a/nodemux/chains/eosrpc.go b/nodemux/chains/eosrpc.go index fae4feb..3a76539 100644 --- a/nodemux/chains/eosrpc.go +++ b/nodemux/chains/eosrpc.go @@ -2,7 +2,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -32,7 +32,7 @@ func (self EOSRPC) StartSync(context context.Context, m *nodemuxcore.Multiplexer } func (self *EOSRPC) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "get_info", nil) var info eosrpcChainInfo @@ -48,7 +48,7 @@ func (self *EOSRPC) GetBlockhead(context context.Context, b *nodemuxcore.Multipl return block, nil } -func (self *EOSRPC) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *EOSRPC) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -300) } diff --git a/nodemux/chains/filecoin.go b/nodemux/chains/filecoin.go index c6b2d8f..664e1d0 100644 --- a/nodemux/chains/filecoin.go +++ b/nodemux/chains/filecoin.go @@ -2,7 +2,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -27,7 +27,7 @@ func (self FilecoinChain) StartSync(context context.Context, m *nodemuxcore.Mult } func (self *FilecoinChain) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "Filecoin.ChainHead", nil) var bt filecoinBlock @@ -43,7 +43,7 @@ func (self *FilecoinChain) GetBlockhead(context context.Context, b *nodemuxcore. return block, nil } -func (self *FilecoinChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *FilecoinChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -3) } diff --git a/nodemux/chains/handshake.go b/nodemux/chains/handshake.go index 67d7026..54e4944 100644 --- a/nodemux/chains/handshake.go +++ b/nodemux/chains/handshake.go @@ -4,7 +4,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -34,7 +34,7 @@ func NewHandshakeChain() *HandshakeChain { } func (self HandshakeChain) GetClientVersion(ctx context.Context, ep *nodemuxcore.Endpoint) (string, error) { - reqmsg := jlib.NewRequestMessage(1, "getinfo", nil) + reqmsg := jsoff.NewRequestMessage(1, "getinfo", nil) var info handshakeInfo err := ep.UnwrapCallRPC(ctx, reqmsg, &info) if err != nil { @@ -48,7 +48,7 @@ func (self HandshakeChain) StartSync(context context.Context, m *nodemuxcore.Mul } func (self *HandshakeChain) GetBlockhead(ctx context.Context, m *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "getchaintips", nil) var chaintips []handshakeBlockhead @@ -69,6 +69,6 @@ func (self *HandshakeChain) GetBlockhead(ctx context.Context, m *nodemuxcore.Mul return nil, nil } -func (self *HandshakeChain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *HandshakeChain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { return m.DefaultRelayRPC(ctx, chain, reqmsg, -2) } diff --git a/nodemux/chains/jsonrpc_cache.go b/nodemux/chains/jsonrpc_cache.go index 8f885f5..4570365 100644 --- a/nodemux/chains/jsonrpc_cache.go +++ b/nodemux/chains/jsonrpc_cache.go @@ -7,13 +7,13 @@ import ( "github.com/go-redis/redis/v8" "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "strings" "time" ) -func jsonrpcCacheGet(ctx context.Context, c *redis.Client, chain nodemuxcore.ChainRef, req *jlib.RequestMessage) (interface{}, bool) { +func jsonrpcCacheGet(ctx context.Context, c *redis.Client, chain nodemuxcore.ChainRef, req *jsoff.RequestMessage) (interface{}, bool) { cacheKey := req.CacheKey(fmt.Sprintf("CC:%s", chain)) data, err := c.Get(ctx, cacheKey).Result() if err != nil { @@ -33,7 +33,7 @@ func jsonrpcCacheGet(ctx context.Context, c *redis.Client, chain nodemuxcore.Cha return res, true } -func jsonrpcCacheUpdate(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, req *jlib.RequestMessage, res *jlib.ResultMessage, expiration time.Duration) { +func jsonrpcCacheUpdate(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, req *jsoff.RequestMessage, res *jsoff.ResultMessage, expiration time.Duration) { if c, ok := m.RedisClientExact(jsonrpcCacheRedisSelector(chain)); ok { cacheKey := req.CacheKey(fmt.Sprintf("CC:%s", chain)) data, err := json.Marshal(res.Result) @@ -54,7 +54,7 @@ func jsonrpcCacheRedisSelector(chain nodemuxcore.ChainRef) string { return fmt.Sprintf("jsonrpc-cache-%s-%s", chain.Namespace, chain.Network) } -func jsonrpcCacheFetchForMethods(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, methods ...string) (bool, *jlib.ResultMessage) { +func jsonrpcCacheFetchForMethods(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, methods ...string) (bool, *jsoff.ResultMessage) { useCache := false for _, method := range methods { if reqmsg.Method == method { @@ -66,7 +66,7 @@ func jsonrpcCacheFetchForMethods(ctx context.Context, m *nodemuxcore.Multiplexer } if c, ok := m.RedisClientExact(jsonrpcCacheRedisSelector(chain)); ok { if resFromCache, ok := jsonrpcCacheGet(ctx, c, chain, reqmsg); ok { - return useCache, jlib.NewResultMessage(reqmsg, resFromCache) + return useCache, jsoff.NewResultMessage(reqmsg, resFromCache) } else { return useCache, nil } diff --git a/nodemux/chains/monero.go b/nodemux/chains/monero.go index 86e8d8d..a865ba4 100644 --- a/nodemux/chains/monero.go +++ b/nodemux/chains/monero.go @@ -4,7 +4,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -29,7 +29,7 @@ func (self MoneroChain) StartSync(context context.Context, m *nodemuxcore.Multip } func (self *MoneroChain) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "get_height", nil) var bt moneroBlock @@ -45,7 +45,7 @@ func (self *MoneroChain) GetBlockhead(context context.Context, b *nodemuxcore.Mu return block, nil } -func (self *MoneroChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *MoneroChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -3) } diff --git a/nodemux/chains/near.go b/nodemux/chains/near.go index 8fe4e55..624207d 100644 --- a/nodemux/chains/near.go +++ b/nodemux/chains/near.go @@ -4,7 +4,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -34,7 +34,7 @@ func (self NearChain) StartSync(context context.Context, m *nodemuxcore.Multiple func (self *NearChain) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { params := map[string]interface{}{"finality": "final"} - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "block", params) var bt nearBlock @@ -50,7 +50,7 @@ func (self *NearChain) GetBlockhead(context context.Context, b *nodemuxcore.Mult return block, nil } -func (self *NearChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *NearChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -3) } diff --git a/nodemux/chains/polkadot.go b/nodemux/chains/polkadot.go index 67e2b61..592d9c8 100644 --- a/nodemux/chains/polkadot.go +++ b/nodemux/chains/polkadot.go @@ -3,7 +3,7 @@ package chains import ( "context" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -42,7 +42,7 @@ func (self PolkadotChain) StartSync(context context.Context, m *nodemuxcore.Mult } func (self *PolkadotChain) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "chain_getHeader", []interface{}{}) var bt polkadotBlock @@ -58,7 +58,7 @@ func (self *PolkadotChain) GetBlockhead(context context.Context, b *nodemuxcore. return block, nil } -func (self *PolkadotChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *PolkadotChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -2) } diff --git a/nodemux/chains/presence_cache.go b/nodemux/chains/presence_cache.go index 43629ac..e968042 100644 --- a/nodemux/chains/presence_cache.go +++ b/nodemux/chains/presence_cache.go @@ -9,7 +9,7 @@ import ( "fmt" "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "math/rand" "time" @@ -69,7 +69,7 @@ func presenceCacheGetEndpoint(ctx context.Context, m *nodemuxcore.Multiplexer, c // match a request message against a given methods list, if matched // and the firsst param is txid then query the cache for an // endpoint that has the txid. -func presenceCacheMatchRequest(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, methods ...string) (*nodemuxcore.Endpoint, bool) { +func presenceCacheMatchRequest(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, methods ...string) (*nodemuxcore.Endpoint, bool) { found := false for _, mth := range methods { if reqmsg.Method == mth { @@ -86,7 +86,7 @@ func presenceCacheMatchRequest(ctx context.Context, m *nodemuxcore.Multiplexer, Txid string // Other params are skiped } - err := jlib.DecodeParams(reqmsg.Params, &txidExtractor) + err := jsoff.DecodeParams(reqmsg.Params, &txidExtractor) if err != nil { reqmsg.Log().Warnf("error decoding params for txid: %s", err) } else if txidExtractor.Txid != "" { diff --git a/nodemux/chains/solana.go b/nodemux/chains/solana.go index 956459f..6adeb11 100644 --- a/nodemux/chains/solana.go +++ b/nodemux/chains/solana.go @@ -2,7 +2,7 @@ package chains import ( "context" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" ) @@ -34,7 +34,7 @@ func (self SolanaChain) StartSync(context context.Context, m *nodemuxcore.Multip } func (self *SolanaChain) GetBlockhead(context context.Context, m *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "getLatestBlockhash", []interface{}{}) var bt solanaBlock @@ -49,7 +49,7 @@ func (self *SolanaChain) GetBlockhead(context context.Context, m *nodemuxcore.Mu return block, nil } -func (self *SolanaChain) DelegateRPC(rootCtx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *SolanaChain) DelegateRPC(rootCtx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return m.DefaultRelayRPC(rootCtx, chain, reqmsg, -10) } diff --git a/nodemux/chains/starcoin.go b/nodemux/chains/starcoin.go index 283e178..7e738e2 100644 --- a/nodemux/chains/starcoin.go +++ b/nodemux/chains/starcoin.go @@ -3,7 +3,7 @@ package chains import ( "context" "github.com/pkg/errors" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "github.com/superisaac/nodemux/core" "net/http" "strconv" @@ -32,7 +32,7 @@ func (self StarcoinChain) StartSync(context context.Context, m *nodemuxcore.Mult } func (self *StarcoinChain) GetBlockhead(context context.Context, b *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "chain.info", nil) var bt starcoinBlock @@ -52,7 +52,7 @@ func (self *StarcoinChain) GetBlockhead(context context.Context, b *nodemuxcore. return block, nil } -func (self *StarcoinChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *StarcoinChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -3) } diff --git a/nodemux/chains/sui.go b/nodemux/chains/sui.go index 447dd1b..74d3b3e 100644 --- a/nodemux/chains/sui.go +++ b/nodemux/chains/sui.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" nodemuxcore "github.com/superisaac/nodemux/core" ) @@ -43,7 +43,7 @@ func NewSuiChain() *SuiChain { } func (self SuiChain) GetClientVersion(context context.Context, ep *nodemuxcore.Endpoint) (string, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "rpc.discover", []interface{}{}) var rpc rpcDiscover err := ep.UnwrapCallRPC(context, reqmsg, &rpc) @@ -62,7 +62,7 @@ func (self *SuiChain) GetBlockhead(context context.Context, b *nodemuxcore.Multi query := &txQuery{} query.Options.ShowRawInput = true - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "suix_queryTransactionBlocks", []interface{}{query, nil, 2, true}) @@ -85,7 +85,7 @@ func (self *SuiChain) GetBlockhead(context context.Context, b *nodemuxcore.Multi return block, nil } -func (self *SuiChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *SuiChain) DelegateRPC(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { // Custom relay methods can be defined here return b.DefaultRelayRPC(rootCtx, chain, reqmsg, -3) } diff --git a/nodemux/chains/web3.go b/nodemux/chains/web3.go index e62c22b..e084cd1 100644 --- a/nodemux/chains/web3.go +++ b/nodemux/chains/web3.go @@ -5,8 +5,8 @@ package chains import ( "context" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/superisaac/jlib" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff" + "github.com/superisaac/jsoff/net" "github.com/superisaac/nodemux/core" "net/http" "reflect" @@ -122,7 +122,7 @@ func NewWeb3Chain() *Web3Chain { } func (self Web3Chain) GetClientVersion(context context.Context, ep *nodemuxcore.Endpoint) (string, error) { - reqmsg := jlib.NewRequestMessage( + reqmsg := jsoff.NewRequestMessage( 1, "web3_clientVersion", nil) var v string err := ep.UnwrapCallRPC(context, reqmsg, &v) @@ -144,8 +144,8 @@ func (self Web3Chain) StartSync(context context.Context, m *nodemuxcore.Multiple } func (self *Web3Chain) GetBlockhead(context context.Context, m *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) (*nodemuxcore.Block, error) { - reqmsg := jlib.NewRequestMessage( - jlib.NewUuid(), "eth_getBlockByNumber", + reqmsg := jsoff.NewRequestMessage( + jsoff.NewUuid(), "eth_getBlockByNumber", []interface{}{"latest", false}) var bt web3Block @@ -171,14 +171,14 @@ func (self *Web3Chain) GetBlockhead(context context.Context, m *nodemuxcore.Mult return block, nil } -func (self *Web3Chain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) { +func (self *Web3Chain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) { if allowed, ok := allowedMethods[reqmsg.Method]; !ok || !allowed { reqmsg.Log().Warnf("relayer method not supported %s", reqmsg.Method) - return jlib.ErrMethodNotFound.ToMessage(reqmsg), nil + return jsoff.ErrMethodNotFound.ToMessage(reqmsg), nil } if reqmsg.Method == "web3_clientVersion" { - return jlib.NewResultMessage(reqmsg, "Web3/1.0.0"), nil + return jsoff.NewResultMessage(reqmsg, "Web3/1.0.0"), nil } //useCache := reqmsg.Method == "eth_getTransactionByHash" || reqmsg.Method == "eth_getTransactionReceipt" @@ -197,7 +197,7 @@ func (self *Web3Chain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplex "eth_getTransactionReceipt"); ok { retmsg, err := endpoint.CallRPC(ctx, reqmsg) if err == nil && useCache && retmsg.IsResult() { - jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jlib.ResultMessage), time.Second*600) + jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jsoff.ResultMessage), time.Second*600) } return retmsg, nil } @@ -210,17 +210,17 @@ func (self *Web3Chain) DelegateRPC(ctx context.Context, m *nodemuxcore.Multiplex //return m.DefaultRelayRPC(ctx, chain, reqmsg, -2) retmsg, err := m.DefaultRelayRPC(ctx, chain, reqmsg, -2) if err == nil && useCache && retmsg.IsResult() { - jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jlib.ResultMessage), time.Second*600) + jsonrpcCacheUpdate(ctx, m, chain, reqmsg, retmsg.(*jsoff.ResultMessage), time.Second*600) } return retmsg, nil } -func (self *Web3Chain) findBlockHeight(reqmsg *jlib.RequestMessage) (int, bool) { +func (self *Web3Chain) findBlockHeight(reqmsg *jsoff.RequestMessage) (int, bool) { // the first argument is a hexlified block number or latest or pending var bh struct { Height string } - if err := jlib.DecodeParams(reqmsg.Params, &bh); err == nil && bh.Height != "" { + if err := jsoff.DecodeParams(reqmsg.Params, &bh); err == nil && bh.Height != "" { if bh.Height == "latest" || bh.Height == "pending" { return 0, true } @@ -232,7 +232,7 @@ func (self *Web3Chain) findBlockHeight(reqmsg *jlib.RequestMessage) (int, bool) } func (self *Web3Chain) subscribeBlockhead(rootCtx context.Context, m *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) { - wsClient, ok := ep.JSONRPCRelayer().(*jlibhttp.WSClient) + wsClient, ok := ep.JSONRPCRelayer().(*jsoffnet.WSClient) if !ok { ep.Log().Panicf("client is not websocket, client is %s", reflect.TypeOf(ep.JSONRPCRelayer())) @@ -240,13 +240,13 @@ func (self *Web3Chain) subscribeBlockhead(rootCtx context.Context, m *nodemuxcor //return errors.New("client is not websocket") } - wsClient.OnMessage(func(msg jlib.Message) { - ntf, ok := msg.(*jlib.NotifyMessage) + wsClient.OnMessage(func(msg jsoff.Message) { + ntf, ok := msg.(*jsoff.NotifyMessage) if !ok && ntf.Method != "eth_subscription" || len(ntf.Params) == 0 { return } var headSub web3HeadSub - err := jlib.DecodeInterface(ntf.Params[0], &headSub) + err := jsoff.DecodeInterface(ntf.Params[0], &headSub) if err != nil { ep.Log().Warnf("decode head sub error %s", err) } else { @@ -289,7 +289,7 @@ func (self *Web3Chain) subscribeBlockhead(rootCtx context.Context, m *nodemuxcor } } -func (self *Web3Chain) connectAndSub(rootCtx context.Context, wsClient *jlibhttp.WSClient, m *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) error { +func (self *Web3Chain) connectAndSub(rootCtx context.Context, wsClient *jsoffnet.WSClient, m *nodemuxcore.Multiplexer, ep *nodemuxcore.Endpoint) error { ctx, cancel := context.WithCancel(rootCtx) defer cancel() @@ -316,8 +316,8 @@ func (self *Web3Chain) connectAndSub(rootCtx context.Context, wsClient *jlibhttp // send sub command var subscribeToken string - submsg := jlib.NewRequestMessage( - jlib.NewUuid(), "eth_subscribe", + submsg := jsoff.NewRequestMessage( + jsoff.NewUuid(), "eth_subscribe", []interface{}{"newHeads"}) err = ep.UnwrapCallRPC(ctx, submsg, &subscribeToken) diff --git a/nodemux/core/endpoint.go b/nodemux/core/endpoint.go index ecf4e12..f9b0287 100644 --- a/nodemux/core/endpoint.go +++ b/nodemux/core/endpoint.go @@ -15,7 +15,7 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff/net" ) // / Create an endpoint instance @@ -276,7 +276,7 @@ func (self *Endpoint) RequestJson(rootCtx context.Context, method string, path s if resp.StatusCode != 200 { self.Log().Warnf("invalid response status %d", resp.StatusCode) - abnResp := &jlibhttp.WrappedResponse{ + abnResp := &jsoffnet.WrappedResponse{ Response: resp, } return errors.Wrap(abnResp, "abnormal response") diff --git a/nodemux/core/jsonrpc_relayer.go b/nodemux/core/jsonrpc_relayer.go index 57d6e12..8a146ee 100644 --- a/nodemux/core/jsonrpc_relayer.go +++ b/nodemux/core/jsonrpc_relayer.go @@ -9,14 +9,14 @@ import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/superisaac/jlib" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff" + "github.com/superisaac/jsoff/net" ) func (self *Endpoint) ensureRPCClient() { if self.rpcClient == nil { - opts := jlibhttp.ClientOptions{Timeout: self.Config.Timeout} - c, err := jlibhttp.NewClient(self.Config.Url, opts) + opts := jsoffnet.ClientOptions{Timeout: self.Config.Timeout} + c, err := jsoffnet.NewClient(self.Config.Url, opts) if err != nil { panic(err) } @@ -24,12 +24,12 @@ func (self *Endpoint) ensureRPCClient() { } } -func (self *Endpoint) JSONRPCRelayer() jlibhttp.Client { +func (self *Endpoint) JSONRPCRelayer() jsoffnet.Client { self.ensureRPCClient() return self.rpcClient } -func (self *Endpoint) CallRPC(rootCtx context.Context, reqmsg *jlib.RequestMessage) (jlib.Message, error) { +func (self *Endpoint) CallRPC(rootCtx context.Context, reqmsg *jsoff.RequestMessage) (jsoff.Message, error) { //self.Connect() self.ensureRPCClient() self.incrRelayCount() @@ -58,7 +58,7 @@ func (self *Endpoint) CallRPC(rootCtx context.Context, reqmsg *jlib.RequestMessa return res, err } // CallRPC -func (self *Endpoint) UnwrapCallRPC(rootCtx context.Context, reqmsg *jlib.RequestMessage, output interface{}) error { +func (self *Endpoint) UnwrapCallRPC(rootCtx context.Context, reqmsg *jsoff.RequestMessage, output interface{}) error { //self.Connect() self.ensureRPCClient() start := time.Now() @@ -70,7 +70,7 @@ func (self *Endpoint) UnwrapCallRPC(rootCtx context.Context, reqmsg *jlib.Reques "method": reqmsg.Method, "timeSpentMS": delta.Milliseconds(), } - var rpcErr *jlib.RPCError + var rpcErr *jsoff.RPCError if err != nil { fields["err"] = err.Error() } else if errors.As(err, &rpcErr) { diff --git a/nodemux/core/multiplexer.go b/nodemux/core/multiplexer.go index 524c1b7..0046359 100644 --- a/nodemux/core/multiplexer.go +++ b/nodemux/core/multiplexer.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" - "github.com/superisaac/jlib" + "github.com/superisaac/jsoff" "net/http" //"sync" ) @@ -16,7 +16,7 @@ var ( ) var ( - ErrNotAvailable = &jlib.RPCError{Code: -32060, Message: "not available"} + ErrNotAvailable = &jsoff.RPCError{Code: -32060, Message: "not available"} ) func GetMultiplexer() *Multiplexer { @@ -184,8 +184,8 @@ func (self *Multiplexer) LoadFromConfig(nbcfg *NodemuxConfig) { func (self *Multiplexer) DefaultRelayRPC( rootCtx context.Context, chain ChainRef, - reqmsg *jlib.RequestMessage, - overHeight int) (jlib.Message, error) { + reqmsg *jsoff.RequestMessage, + overHeight int) (jsoff.Message, error) { ep, found := self.SelectOverHeight(chain, reqmsg.Method, overHeight) if !found { if overHeight > 0 { diff --git a/nodemux/core/types.go b/nodemux/core/types.go index 2565aeb..d984b54 100644 --- a/nodemux/core/types.go +++ b/nodemux/core/types.go @@ -3,8 +3,8 @@ package nodemuxcore import ( "context" "github.com/go-redis/redis/v8" - "github.com/superisaac/jlib" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff" + "github.com/superisaac/jsoff/net" "net/http" ) @@ -41,7 +41,7 @@ type Endpoint struct { Blockhead *Block client *http.Client - rpcClient jlibhttp.Client + rpcClient jsoffnet.Client // sync status connected bool @@ -100,7 +100,7 @@ type BlockheadDelegator interface { type RPCDelegator interface { BlockheadDelegator - DelegateRPC(ctx context.Context, b *Multiplexer, chain ChainRef, reqmsg *jlib.RequestMessage, r *http.Request) (jlib.Message, error) + DelegateRPC(ctx context.Context, b *Multiplexer, chain ChainRef, reqmsg *jsoff.RequestMessage, r *http.Request) (jsoff.Message, error) } type RESTDelegator interface { diff --git a/nodemux/go.mod b/nodemux/go.mod index 3effd0d..b4779d0 100644 --- a/nodemux/go.mod +++ b/nodemux/go.mod @@ -1,6 +1,8 @@ module github.com/superisaac/nodemux -go 1.19 +go 1.21 + +toolchain go1.21.3 require ( github.com/ethereum/go-ethereum v1.11.1 @@ -26,6 +28,8 @@ require ( github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect + github.com/mdlayher/socket v0.4.1 // indirect + github.com/mdlayher/vsock v1.2.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect @@ -33,9 +37,11 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.40.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect - golang.org/x/net v0.8.0 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect + github.com/superisaac/jsoff v0.5.7 // indirect + golang.org/x/net v0.9.0 // indirect + golang.org/x/sync v0.1.0 // indirect + golang.org/x/sys v0.7.0 // indirect + golang.org/x/text v0.9.0 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/nodemux/go.sum b/nodemux/go.sum index 1c29e9c..87202f4 100644 --- a/nodemux/go.sum +++ b/nodemux/go.sum @@ -303,6 +303,10 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= +github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= +github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ= +github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= @@ -422,6 +426,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/superisaac/jlib v0.4.2/go.mod h1:mr1uMAKhYPhxvtdKGLksNuVEWzd4WhbT+Z/VW8CVcd8= +github.com/superisaac/jsoff v0.5.7 h1:UtfIB9O102wevJ/QCKGnzneImfrigPVwyT/Ud0VRNjg= +github.com/superisaac/jsoff v0.5.7/go.mod h1:YEc9hn9MgERgdDxnarkhqt1hrtfV0LJZgKWa+uG/HHs= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= @@ -510,6 +517,8 @@ golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -525,6 +534,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -578,6 +589,8 @@ golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -593,6 +606,8 @@ golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/nodemux/server/admin_server.go b/nodemux/server/admin_server.go index 8bd8fdb..0a3f7b6 100644 --- a/nodemux/server/admin_server.go +++ b/nodemux/server/admin_server.go @@ -1,14 +1,14 @@ package server import ( - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff/net" "github.com/superisaac/nodemux/core" "sort" ) -func NewAdminHandler() *jlibhttp.H1Handler { - actor := jlibhttp.NewActor() - actor.OnTyped("nodemux_listEndpoints", func(request *jlibhttp.RPCRequest) ([]nodemuxcore.EndpointInfo, error) { +func NewAdminHandler() *jsoffnet.Http1Handler { + actor := jsoffnet.NewActor() + actor.OnTyped("nodemux_listEndpoints", func(request *jsoffnet.RPCRequest) ([]nodemuxcore.EndpointInfo, error) { m := nodemuxcore.GetMultiplexer() infos := m.ListEndpointInfos() @@ -19,5 +19,5 @@ func NewAdminHandler() *jlibhttp.H1Handler { return infos, nil }) - return jlibhttp.NewH1Handler(actor) + return jsoffnet.NewHttp1Handler(actor) } diff --git a/nodemux/server/config.go b/nodemux/server/config.go index 81413bc..9f99f2f 100644 --- a/nodemux/server/config.go +++ b/nodemux/server/config.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/pkg/errors" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff/net" yaml "gopkg.in/yaml.v2" ) @@ -20,20 +20,20 @@ import ( type MetricsConfig struct { Bind string - Auth *jlibhttp.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` - TLS *jlibhttp.TLSConfig `yaml:"tls:omitempty" json:"tls:omitempty"` + Auth *jsoffnet.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` + TLS *jsoffnet.TLSConfig `yaml:"tls:omitempty" json:"tls:omitempty"` } type AdminConfig struct { - Auth *jlibhttp.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` + Auth *jsoffnet.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` } type EntrypointConfig struct { Account string Chain string Bind string - Auth *jlibhttp.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` - TLS *jlibhttp.TLSConfig `yaml:"tls,omitempty" json:"tls,omitempty"` + Auth *jsoffnet.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` + TLS *jsoffnet.TLSConfig `yaml:"tls,omitempty" json:"tls,omitempty"` } type RatelimitConfig struct { @@ -50,10 +50,10 @@ type AccountConfig struct { type ServerConfig struct { Bind string `yaml:"version,omitempty" json:"version,omitempty"` - TLS *jlibhttp.TLSConfig `yaml:"tls,omitempty" json:"tls,omitempty"` + TLS *jsoffnet.TLSConfig `yaml:"tls,omitempty" json:"tls,omitempty"` Admin *AdminConfig `yaml:"admin,omitempty" json:"admin,omitempty"` Metrics *MetricsConfig `yaml:"metrics,omitempty" json:"metrics,omitempty"` - Auth *jlibhttp.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` + Auth *jsoffnet.AuthConfig `yaml:"auth,omitempty" json:"auth,omitempty"` Entrypoints []EntrypointConfig `yaml:"entrypoints,omitempty" json:"entrypoints,omitempty"` Ratelimit RatelimitConfig `yaml:"ratelimit,omitempty" json:"ratelimit,omitempty"` Accounts map[string]AccountConfig `yaml:"accounts,omitempty" json:"accounts,omitempty"` diff --git a/nodemux/server/http_server.go b/nodemux/server/http_server.go index f7b77f5..ed80da2 100644 --- a/nodemux/server/http_server.go +++ b/nodemux/server/http_server.go @@ -4,7 +4,7 @@ import ( "context" "github.com/prometheus/client_golang/prometheus/promhttp" log "github.com/sirupsen/logrus" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff/net" "net/http" ) @@ -14,8 +14,8 @@ func requestLog(r *http.Request) *log.Entry { }) } -func startServer(rootCtx context.Context, bind string, handler http.Handler, tlsConfigs ...*jlibhttp.TLSConfig) error { - return jlibhttp.ListenAndServe( +func startServer(rootCtx context.Context, bind string, handler http.Handler, tlsConfigs ...*jsoffnet.TLSConfig) error { + return jsoffnet.ListenAndServe( rootCtx, bind, handler, tlsConfigs...) @@ -28,7 +28,7 @@ func startMetricsServer(rootCtx context.Context, serverCfg *ServerConfig) { return } - handler := jlibhttp.NewAuthHandler( + handler := jsoffnet.NewAuthHandler( serverCfg.Metrics.Auth, promhttp.Handler()) err := startServer( @@ -40,15 +40,15 @@ func startMetricsServer(rootCtx context.Context, serverCfg *ServerConfig) { } } -func adminHandler(rootCtx context.Context, authCfg *jlibhttp.AuthConfig, next http.Handler) http.Handler { - h1 := jlibhttp.NewAuthHandler(authCfg, next) +func adminHandler(rootCtx context.Context, authCfg *jsoffnet.AuthConfig, next http.Handler) http.Handler { + h1 := jsoffnet.NewAuthHandler(authCfg, next) return h1 } -func relayHandler(rootCtx context.Context, authCfg *jlibhttp.AuthConfig, next http.Handler) http.Handler { +func relayHandler(rootCtx context.Context, authCfg *jsoffnet.AuthConfig, next http.Handler) http.Handler { h0 := NewRatelimitHandler(rootCtx, next) h1 := NewAccHandler(rootCtx, h0) - h2 := jlibhttp.NewAuthHandler(authCfg, h1) + h2 := jsoffnet.NewAuthHandler(authCfg, h1) return h2 } @@ -59,7 +59,7 @@ func StartHTTPServer(rootCtx context.Context, serverCfg *ServerConfig) { } log.Infof("start http proxy at %s", bind) - var adminAuth *jlibhttp.AuthConfig + var adminAuth *jsoffnet.AuthConfig if serverCfg.Admin != nil { adminAuth = serverCfg.Admin.Auth } diff --git a/nodemux/server/jsonrpc_relayer.go b/nodemux/server/jsonrpc_relayer.go index 7778f6c..4e3aaf8 100644 --- a/nodemux/server/jsonrpc_relayer.go +++ b/nodemux/server/jsonrpc_relayer.go @@ -3,8 +3,8 @@ package server import ( "context" log "github.com/sirupsen/logrus" - "github.com/superisaac/jlib" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff" + "github.com/superisaac/jsoff/net" "github.com/superisaac/nodemux/core" "net/http" "time" @@ -14,7 +14,7 @@ import ( type JSONRPCRelayer struct { rootCtx context.Context acc *Acc - rpcHandler *jlibhttp.H1Handler + rpcHandler *jsoffnet.Http1Handler } func NewJSONRPCRelayer(rootCtx context.Context) *JSONRPCRelayer { @@ -22,15 +22,15 @@ func NewJSONRPCRelayer(rootCtx context.Context) *JSONRPCRelayer { rootCtx: rootCtx, } - rpcHandler := jlibhttp.NewH1Handler(nil) - rpcHandler.Actor.OnMissing(func(req *jlibhttp.RPCRequest) (interface{}, error) { + rpcHandler := jsoffnet.NewHttp1Handler(nil) + rpcHandler.Actor.OnMissing(func(req *jsoffnet.RPCRequest) (interface{}, error) { return relayer.delegateRPC(req) }) relayer.rpcHandler = rpcHandler return relayer } -func (self *JSONRPCRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{}, error) { +func (self *JSONRPCRelayer) delegateRPC(req *jsoffnet.RPCRequest) (interface{}, error) { r := req.HttpRequest() msg := req.Msg() acc := self.acc @@ -38,7 +38,7 @@ func (self *JSONRPCRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{}, if acc == nil { acc = AccFromContext(r.Context()) if acc == nil { - return nil, jlibhttp.SimpleResponse{ + return nil, jsoffnet.SimpleResponse{ Code: 404, Body: []byte("acc not found"), } @@ -46,18 +46,18 @@ func (self *JSONRPCRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{}, } if !msg.IsRequest() { - return nil, jlibhttp.SimpleResponse{ + return nil, jsoffnet.SimpleResponse{ Code: 400, Body: []byte("bad request"), } } - reqmsg, _ := msg.(*jlib.RequestMessage) + reqmsg, _ := msg.(*jsoff.RequestMessage) m := nodemuxcore.GetMultiplexer() delegator := nodemuxcore.GetDelegatorFactory().GetRPCDelegator(acc.Chain.Namespace) if delegator == nil { - return nil, jlibhttp.SimpleResponse{ + return nil, jsoffnet.SimpleResponse{ Code: 404, Body: []byte("backend not found"), } diff --git a/nodemux/server/jsonrpcws_relayer.go b/nodemux/server/jsonrpcws_relayer.go index 302397d..80e6056 100644 --- a/nodemux/server/jsonrpcws_relayer.go +++ b/nodemux/server/jsonrpcws_relayer.go @@ -3,22 +3,22 @@ package server import ( "context" "github.com/pkg/errors" - "github.com/superisaac/jlib" - "github.com/superisaac/jlib/http" + "github.com/superisaac/jsoff" + "github.com/superisaac/jsoff/net" "github.com/superisaac/nodemux/core" "net/http" "net/url" ) var ( - wsPairs = make(map[string]*jlibhttp.WSClient) + wsPairs = make(map[string]*jsoffnet.WSClient) ) // JSONRPC Handler type JSONRPCWSRelayer struct { rootCtx context.Context acc *Acc - rpcHandler *jlibhttp.WSHandler + rpcHandler *jsoffnet.WSHandler } func NewJSONRPCWSRelayer(rootCtx context.Context) *JSONRPCWSRelayer { @@ -26,11 +26,11 @@ func NewJSONRPCWSRelayer(rootCtx context.Context) *JSONRPCWSRelayer { rootCtx: rootCtx, } - rpcHandler := jlibhttp.NewWSHandler(rootCtx, nil) - rpcHandler.Actor.OnClose(func(r *http.Request, s jlibhttp.RPCSession) { - relayer.onClose(r, s) + rpcHandler := jsoffnet.NewWSHandler(rootCtx, nil) + rpcHandler.Actor.OnClose(func(s jsoffnet.RPCSession) { + relayer.onClose(s) }) - rpcHandler.Actor.OnMissing(func(req *jlibhttp.RPCRequest) (interface{}, error) { + rpcHandler.Actor.OnMissing(func(req *jsoffnet.RPCRequest) (interface{}, error) { r := req.HttpRequest() acc := AccFromContext(r.Context()) accName := "" @@ -49,7 +49,7 @@ func NewJSONRPCWSRelayer(rootCtx context.Context) *JSONRPCWSRelayer { if err != nil { return nil, err } else if !ok { - return nil, jlibhttp.SimpleResponse{ + return nil, jsoffnet.SimpleResponse{ Code: 429, Body: []byte("rate limit exceeded!"), } @@ -60,12 +60,12 @@ func NewJSONRPCWSRelayer(rootCtx context.Context) *JSONRPCWSRelayer { return relayer } -func (self *JSONRPCWSRelayer) onClose(r *http.Request, s jlibhttp.RPCSession) { +func (self *JSONRPCWSRelayer) onClose(s jsoffnet.RPCSession) { delete(wsPairs, s.SessionID()) metricsWSPairsCount.Set(float64(len(wsPairs))) } -func (self *JSONRPCWSRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{}, error) { +func (self *JSONRPCWSRelayer) delegateRPC(req *jsoffnet.RPCRequest) (interface{}, error) { r := req.HttpRequest() msg := req.Msg() @@ -78,7 +78,7 @@ func (self *JSONRPCWSRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{} if acc == nil { acc = AccFromContext(r.Context()) if acc == nil { - return nil, jlibhttp.SimpleResponse{ + return nil, jsoffnet.SimpleResponse{ Code: 404, Body: []byte("acc not found"), } @@ -99,12 +99,12 @@ func (self *JSONRPCWSRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{} if err != nil { return nil, err } - destWs := jlibhttp.NewWSClient(u) - destWs.OnMessage(func(m jlib.Message) { + destWs := jsoffnet.NewWSClient(u) + destWs.OnMessage(func(m jsoff.Message) { session.Send(m) }) destWs.OnClose(func() { - self.onClose(r, session) + self.onClose(session) }) wsPairs[session.SessionID()] = destWs metricsWSPairsCount.Set(float64(len(wsPairs))) @@ -114,9 +114,9 @@ func (self *JSONRPCWSRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{} // if no dest websocket connection is available and msg is a request message // it's still ok to deliver the message to http endpoints delegator := nodemuxcore.GetDelegatorFactory().GetRPCDelegator(acc.Chain.Namespace) - reqmsg, _ := msg.(*jlib.RequestMessage) + reqmsg, _ := msg.(*jsoff.RequestMessage) if delegator == nil { - return nil, jlibhttp.SimpleResponse{ + return nil, jsoffnet.SimpleResponse{ Code: 404, Body: []byte("backend not found"), } @@ -126,7 +126,7 @@ func (self *JSONRPCWSRelayer) delegateRPC(req *jlibhttp.RPCRequest) (interface{} return resmsg, err } else { // the last way, return back - return nil, jlibhttp.SimpleResponse{ + return nil, jsoffnet.SimpleResponse{ Code: 400, Body: []byte("no websocket upstreams"), }