From 850354c52967a07c3d7235756bffb4652fb469a6 Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Fri, 6 Oct 2023 05:12:55 +0300 Subject: [PATCH] done expose-all-new-rpc --- .fixme/log | 6 +-- .gitignore | 5 ++- hbs2-peer/app/CLI/RefChan.hs | 4 +- hbs2-peer/app/PeerMain.hs | 10 +++-- hbs2-peer/app/RPC2.hs | 11 ++++- hbs2-peer/app/RPC2/Announce.hs | 2 +- hbs2-peer/app/RPC2/Die.hs | 2 +- hbs2-peer/app/RPC2/Fetch.hs | 2 +- hbs2-peer/app/RPC2/LogLevel.hs | 8 +--- hbs2-peer/app/RPC2/Peer.hs | 6 +-- hbs2-peer/app/RPC2/Peers.hs | 2 +- hbs2-peer/app/RPC2/PexInfo.hs | 2 +- hbs2-peer/app/RPC2/Ping.hs | 2 +- hbs2-peer/app/RPC2/Poke.hs | 2 +- hbs2-peer/app/RPC2/RefChan.hs | 35 +--------------- hbs2-peer/app/RPC2/RefLog.hs | 21 +--------- hbs2-peer/hbs2-peer.cabal | 5 ++- hbs2-peer/lib/HBS2/Peer/RPC/API.hs | 3 -- .../API.hs => lib/HBS2/Peer/RPC/API/Peer.hs} | 9 ++++- hbs2-peer/lib/HBS2/Peer/RPC/API/RefChan.hs | 40 +++++++++++++++++++ hbs2-peer/lib/HBS2/Peer/RPC/API/RefLog.hs | 25 ++++++++++++ 21 files changed, 114 insertions(+), 88 deletions(-) delete mode 100644 hbs2-peer/lib/HBS2/Peer/RPC/API.hs rename hbs2-peer/{app/RPC2/Peer/API.hs => lib/HBS2/Peer/RPC/API/Peer.hs} (87%) create mode 100644 hbs2-peer/lib/HBS2/Peer/RPC/API/RefChan.hs create mode 100644 hbs2-peer/lib/HBS2/Peer/RPC/API/RefLog.hs diff --git a/.fixme/log b/.fixme/log index dbfeb0d7..e559070d 100644 --- a/.fixme/log +++ b/.fixme/log @@ -1,5 +1,3 @@ -(fixme-set "assigned" "voidlizard" "CmfGGmDAuC") -(fixme-set "assigned" "voidlizard" "4Bm5kS8t54" ) -(fixme-set "assigned" "voidlizard" "8i2gUFTTnH" ) -(fixme-set "assigned" "voidlizard" "CPhvijEXN2" ) +(fixme-set "assigned" "voidlizard" "DGW8fuaufG" ) +(fixme-set "workflow" "test" "DGW8fuaufG") diff --git a/.gitignore b/.gitignore index b2a40f47..2972ae39 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ hbs2.prof .fixme/state.db result # VS Code -settings.json \ No newline at end of file +settings.json + +cabal.project.local + diff --git a/hbs2-peer/app/CLI/RefChan.hs b/hbs2-peer/app/CLI/RefChan.hs index 94077316..75b2357c 100644 --- a/hbs2-peer/app/CLI/RefChan.hs +++ b/hbs2-peer/app/CLI/RefChan.hs @@ -11,8 +11,10 @@ import HBS2.Net.Proto.Service import HBS2.OrDie +import HBS2.Peer.RPC.API.RefChan + import CLI.Common -import RPC2.RefChan +import RPC2() import Options.Applicative import Data.ByteString qualified as BS diff --git a/hbs2-peer/app/PeerMain.hs b/hbs2-peer/app/PeerMain.hs index 0bd91806..bd09fad2 100644 --- a/hbs2-peer/app/PeerMain.hs +++ b/hbs2-peer/app/PeerMain.hs @@ -68,11 +68,13 @@ import Log import HBS2.Peer.RPC.Internal.Types() import HBS2.Peer.RPC.Internal.Storage() -import HBS2.Peer.RPC.API.Storage -import RPC2.Peer -import RPC2.RefLog -import RPC2.RefChan +import HBS2.Peer.RPC.API.Storage +import HBS2.Peer.RPC.API.Peer +import HBS2.Peer.RPC.API.RefLog +import HBS2.Peer.RPC.API.RefChan + +import RPC2(RPC2Context(..)) import Codec.Serialise as Serialise import Control.Concurrent.STM diff --git a/hbs2-peer/app/RPC2.hs b/hbs2-peer/app/RPC2.hs index e3a79c7a..c56ea3f8 100644 --- a/hbs2-peer/app/RPC2.hs +++ b/hbs2-peer/app/RPC2.hs @@ -1,4 +1,11 @@ -module RPC2 where +module RPC2 + ( module RPC2.Peer + , module RPC2.RefLog + , module RPC2.RefChan + ) where -import Data.Config.Suckless.KeyValue() + +import RPC2.Peer +import RPC2.RefLog +import RPC2.RefChan diff --git a/hbs2-peer/app/RPC2/Announce.hs b/hbs2-peer/app/RPC2/Announce.hs index 7a28131d..6d439968 100644 --- a/hbs2-peer/app/RPC2/Announce.hs +++ b/hbs2-peer/app/RPC2/Announce.hs @@ -11,7 +11,7 @@ import HBS2.System.Logger.Simple import SendBlockAnnounce import HBS2.Peer.RPC.Internal.Types -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer instance (MonadIO m,HasRpcContext PeerAPI RPC2Context m) => HandleMethod m RpcAnnounce where diff --git a/hbs2-peer/app/RPC2/Die.hs b/hbs2-peer/app/RPC2/Die.hs index b84f2c43..9f54cf7d 100644 --- a/hbs2-peer/app/RPC2/Die.hs +++ b/hbs2-peer/app/RPC2/Die.hs @@ -8,7 +8,7 @@ import HBS2.System.Logger.Simple import Data.Config.Suckless.KeyValue import HBS2.Peer.RPC.Internal.Types -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer import System.Exit qualified as Exit import Control.Concurrent.Async diff --git a/hbs2-peer/app/RPC2/Fetch.hs b/hbs2-peer/app/RPC2/Fetch.hs index 305b9e35..cc66d88e 100644 --- a/hbs2-peer/app/RPC2/Fetch.hs +++ b/hbs2-peer/app/RPC2/Fetch.hs @@ -9,7 +9,7 @@ import HBS2.Net.Proto.Service import HBS2.System.Logger.Simple import HBS2.Peer.RPC.Internal.Types -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer instance (MonadIO m, HasRpcContext PeerAPI RPC2Context m) => HandleMethod m RpcFetch where type instance Input RpcFetch = HashRef diff --git a/hbs2-peer/app/RPC2/LogLevel.hs b/hbs2-peer/app/RPC2/LogLevel.hs index 192433d8..c0ab2bf4 100644 --- a/hbs2-peer/app/RPC2/LogLevel.hs +++ b/hbs2-peer/app/RPC2/LogLevel.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} module RPC2.LogLevel where import HBS2.Prelude.Plated @@ -5,16 +6,11 @@ import HBS2.Net.Proto.Service import Log -import HBS2.Peer.RPC.Internal.Types -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer import HBS2.System.Logger.Simple import Codec.Serialise -data SetLogging = - DebugOn Bool - | TraceOn Bool - deriving (Generic,Eq,Show) instance Serialise SetLogging diff --git a/hbs2-peer/app/RPC2/Peer.hs b/hbs2-peer/app/RPC2/Peer.hs index 0a39b854..2174aa5c 100644 --- a/hbs2-peer/app/RPC2/Peer.hs +++ b/hbs2-peer/app/RPC2/Peer.hs @@ -1,17 +1,17 @@ module RPC2.Peer ( module RPC2.Peer - , module RPC2.Peer.API + , module HBS2.Peer.RPC.API.Peer , module RPC2.LogLevel -- , SetLogging(..) ) where -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer import RPC2.Announce() import RPC2.Fetch() import RPC2.Peers() import RPC2.PexInfo() import RPC2.Ping() -import RPC2.Poke +import RPC2.Poke() import RPC2.RefLog() import RPC2.RefChan() import RPC2.Die() diff --git a/hbs2-peer/app/RPC2/Peers.hs b/hbs2-peer/app/RPC2/Peers.hs index b7b2789a..225a93d5 100644 --- a/hbs2-peer/app/RPC2/Peers.hs +++ b/hbs2-peer/app/RPC2/Peers.hs @@ -15,7 +15,7 @@ import HBS2.Net.Proto.Definition() import PeerTypes import HBS2.Peer.RPC.Internal.Types -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer import Control.Monad import Lens.Micro.Platform diff --git a/hbs2-peer/app/RPC2/PexInfo.hs b/hbs2-peer/app/RPC2/PexInfo.hs index 6add1522..16548e19 100644 --- a/hbs2-peer/app/RPC2/PexInfo.hs +++ b/hbs2-peer/app/RPC2/PexInfo.hs @@ -11,7 +11,7 @@ import HBS2.Net.Proto.Definition() import HBS2.Net.Proto.PeerExchange import HBS2.Peer.RPC.Internal.Types -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer instance ( MonadIO m , HasRpcContext PeerAPI RPC2Context m diff --git a/hbs2-peer/app/RPC2/Ping.hs b/hbs2-peer/app/RPC2/Ping.hs index 266604c2..6c99528b 100644 --- a/hbs2-peer/app/RPC2/Ping.hs +++ b/hbs2-peer/app/RPC2/Ping.hs @@ -13,7 +13,7 @@ import HBS2.System.Logger.Simple import HBS2.Peer.RPC.Internal.Types import PeerTypes -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer instance (MonadIO m, HasRpcContext PeerAPI RPC2Context m) => HandleMethod m RpcPing where diff --git a/hbs2-peer/app/RPC2/Poke.hs b/hbs2-peer/app/RPC2/Poke.hs index 92e9e496..34f8b733 100644 --- a/hbs2-peer/app/RPC2/Poke.hs +++ b/hbs2-peer/app/RPC2/Poke.hs @@ -8,7 +8,7 @@ import HBS2.Net.Proto.Service import HBS2.System.Logger.Simple import HBS2.Peer.RPC.Internal.Types -import RPC2.Peer.API +import HBS2.Peer.RPC.API.Peer instance ( MonadIO m diff --git a/hbs2-peer/app/RPC2/RefChan.hs b/hbs2-peer/app/RPC2/RefChan.hs index 954f9bb1..6426c2de 100644 --- a/hbs2-peer/app/RPC2/RefChan.hs +++ b/hbs2-peer/app/RPC2/RefChan.hs @@ -12,54 +12,21 @@ import HBS2.Base58 import HBS2.Data.Types.Refs (HashRef(..)) import HBS2.Net.Proto.Definition() import HBS2.Net.Proto.Service -import HBS2.Net.Proto.Types import HBS2.Data.Types.SignedBox import HBS2.Net.Proto.RefChan import HBS2.Net.Messaging.Unix import HBS2.Storage +import HBS2.Peer.RPC.API.RefChan import HBS2.Peer.RPC.Internal.Types import HBS2.System.Logger.Simple import PeerTypes -import Data.ByteString.Lazy (ByteString) import Data.ByteString qualified as BS import Data.Functor -import Codec.Serialise import Control.Monad.Reader --- NOTE: refchan-head-endpoints -data RpcRefChanHeadGet -data RpcRefChanHeadFetch -data RpcRefChanHeadPost - --- NOTE: refchan-endpoints -data RpcRefChanFetch -data RpcRefChanGet -data RpcRefChanPropose - -data RpcRefChanNotify - -type RefChanAPI = '[ RpcRefChanHeadGet - , RpcRefChanHeadFetch - , RpcRefChanHeadPost - , RpcRefChanGet - , RpcRefChanFetch - , RpcRefChanPropose - , RpcRefChanNotify - ] - - -type RefChanAPIProto = 0xDA2374630001 - --- FIXME: hbs2-peer-protocols-to- -instance HasProtocol UNIX (ServiceProto RefChanAPI UNIX) where - type instance ProtocolId (ServiceProto RefChanAPI UNIX) = RefChanAPIProto - type instance Encoded UNIX = ByteString - decode = either (const Nothing) Just . deserialiseOrFail - encode = serialise - type RefChanContext m = (MonadIO m, HasRpcContext RefChanAPI RPC2Context m) instance (Monad m) diff --git a/hbs2-peer/app/RPC2/RefLog.hs b/hbs2-peer/app/RPC2/RefLog.hs index 19536ed9..a157a7da 100644 --- a/hbs2-peer/app/RPC2/RefLog.hs +++ b/hbs2-peer/app/RPC2/RefLog.hs @@ -15,7 +15,6 @@ import HBS2.Events import HBS2.Net.Proto.Definition() import HBS2.Net.Proto.RefLog import HBS2.Net.Proto.Service -import HBS2.Net.Proto.Types import HBS2.Storage import HBS2.Net.Messaging.Unix @@ -24,32 +23,14 @@ import PeerTypes import RefLog (doRefLogBroadCast) import HBS2.Peer.RPC.Internal.Types +import HBS2.Peer.RPC.API.RefLog import Data.Functor import Lens.Micro.Platform -import Data.ByteString.Lazy ( ByteString ) -import Codec.Serialise import Control.Monad.Reader -data RpcRefLogGet -data RpcRefLogFetch -data RpcRefLogPost - -type RefLogAPI = '[ RpcRefLogGet - , RpcRefLogFetch - , RpcRefLogPost - ] - - type RefLogContext m = (MonadIO m, HasRpcContext RefLogAPI RPC2Context m) -instance HasProtocol UNIX (ServiceProto RefLogAPI UNIX) where - type instance ProtocolId (ServiceProto RefLogAPI UNIX) = 0xDA2371620001 - type instance Encoded UNIX = ByteString - decode = either (const Nothing) Just . deserialiseOrFail - encode = serialise - - instance (Monad m) => HasRpcContext RefLogAPI RPC2Context (ResponseM UNIX (ReaderT RPC2Context m)) where -- type instance RpcContext RefLogAPI = RPC2Context diff --git a/hbs2-peer/hbs2-peer.cabal b/hbs2-peer/hbs2-peer.cabal index 13ba5cc9..527989c1 100644 --- a/hbs2-peer/hbs2-peer.cabal +++ b/hbs2-peer/hbs2-peer.cabal @@ -133,7 +133,9 @@ library exposed-modules: HBS2.Peer.RPC.Class - HBS2.Peer.RPC.API + HBS2.Peer.RPC.API.Peer + HBS2.Peer.RPC.API.RefLog + HBS2.Peer.RPC.API.RefChan HBS2.Peer.RPC.API.Storage HBS2.Peer.RPC.Client.Unix HBS2.Peer.RPC.Client.StorageClient @@ -165,7 +167,6 @@ executable hbs2-peer , Fetch , Log , RPC2 - , RPC2.Peer.API , RPC2.Peer , RPC2.Poke , RPC2.Announce diff --git a/hbs2-peer/lib/HBS2/Peer/RPC/API.hs b/hbs2-peer/lib/HBS2/Peer/RPC/API.hs deleted file mode 100644 index 65f73f34..00000000 --- a/hbs2-peer/lib/HBS2/Peer/RPC/API.hs +++ /dev/null @@ -1,3 +0,0 @@ -module HBS2.Peer.RPC.API where - - diff --git a/hbs2-peer/app/RPC2/Peer/API.hs b/hbs2-peer/lib/HBS2/Peer/RPC/API/Peer.hs similarity index 87% rename from hbs2-peer/app/RPC2/Peer/API.hs rename to hbs2-peer/lib/HBS2/Peer/RPC/API/Peer.hs index 22073e12..c606cc1b 100644 --- a/hbs2-peer/app/RPC2/Peer/API.hs +++ b/hbs2-peer/lib/HBS2/Peer/RPC/API/Peer.hs @@ -1,5 +1,6 @@ -module RPC2.Peer.API where +module HBS2.Peer.RPC.API.Peer where +import HBS2.Prelude.Plated import HBS2.Net.Messaging.Unix import HBS2.Net.Proto.Service import HBS2.Actors.Peer @@ -40,3 +41,9 @@ instance (Monad m) -- type instance RpcContext PeerAPI = RPC2Context getRpcContext = lift ask + +data SetLogging = + DebugOn Bool + | TraceOn Bool + deriving (Generic,Eq,Show) + diff --git a/hbs2-peer/lib/HBS2/Peer/RPC/API/RefChan.hs b/hbs2-peer/lib/HBS2/Peer/RPC/API/RefChan.hs new file mode 100644 index 00000000..402acf77 --- /dev/null +++ b/hbs2-peer/lib/HBS2/Peer/RPC/API/RefChan.hs @@ -0,0 +1,40 @@ +module HBS2.Peer.RPC.API.RefChan where + +import HBS2.Net.Proto.Service +import HBS2.Net.Messaging.Unix (UNIX) + +import Data.ByteString.Lazy ( ByteString ) +import Codec.Serialise + +-- NOTE: refchan-head-endpoints +data RpcRefChanHeadGet +data RpcRefChanHeadFetch +data RpcRefChanHeadPost + +-- NOTE: refchan-endpoints +data RpcRefChanFetch +data RpcRefChanGet +data RpcRefChanPropose + +data RpcRefChanNotify + +type RefChanAPI = '[ RpcRefChanHeadGet + , RpcRefChanHeadFetch + , RpcRefChanHeadPost + , RpcRefChanGet + , RpcRefChanFetch + , RpcRefChanPropose + , RpcRefChanNotify + ] + + +type RefChanAPIProto = 0xDA2374630001 + +-- FIXME: hbs2-peer-protocols-to- +instance HasProtocol UNIX (ServiceProto RefChanAPI UNIX) where + type instance ProtocolId (ServiceProto RefChanAPI UNIX) = RefChanAPIProto + type instance Encoded UNIX = ByteString + decode = either (const Nothing) Just . deserialiseOrFail + encode = serialise + + diff --git a/hbs2-peer/lib/HBS2/Peer/RPC/API/RefLog.hs b/hbs2-peer/lib/HBS2/Peer/RPC/API/RefLog.hs new file mode 100644 index 00000000..9964238a --- /dev/null +++ b/hbs2-peer/lib/HBS2/Peer/RPC/API/RefLog.hs @@ -0,0 +1,25 @@ +module HBS2.Peer.RPC.API.RefLog where + +import HBS2.Net.Messaging.Unix +import HBS2.Net.Proto.Service + +import Data.ByteString.Lazy (ByteString) +import Codec.Serialise + +data RpcRefLogGet +data RpcRefLogFetch +data RpcRefLogPost + +type RefLogAPI = '[ RpcRefLogGet + , RpcRefLogFetch + , RpcRefLogPost + ] + + + +instance HasProtocol UNIX (ServiceProto RefLogAPI UNIX) where + type instance ProtocolId (ServiceProto RefLogAPI UNIX) = 0xDA2371620001 + type instance Encoded UNIX = ByteString + decode = either (const Nothing) Just . deserialiseOrFail + encode = serialise +