mirror of https://github.com/voidlizard/hbs2
wip, dump refchan head block
This commit is contained in:
parent
5103d37963
commit
04a274f7cc
|
@ -18,16 +18,15 @@ import Data.Config.Suckless
|
||||||
|
|
||||||
-- import HBS2.System.Logger.Simple
|
-- import HBS2.System.Logger.Simple
|
||||||
|
|
||||||
-- import Data.Maybe
|
import Codec.Serialise
|
||||||
-- import Data.Hashable
|
import Control.Monad.Identity
|
||||||
import Data.Text qualified as Text
|
import Control.Monad.Trans.Maybe
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import Data.ByteString.Lazy qualified as LBS
|
import Data.ByteString.Lazy qualified as LBS
|
||||||
-- import Type.Reflection (someTypeRep)
|
|
||||||
import Data.Either
|
import Data.Either
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Data.Text qualified as Text
|
||||||
import Lens.Micro.Platform
|
import Lens.Micro.Platform
|
||||||
import Codec.Serialise
|
|
||||||
|
|
||||||
{- HLINT ignore "Use newtype instead of data" -}
|
{- HLINT ignore "Use newtype instead of data" -}
|
||||||
|
|
||||||
|
@ -56,8 +55,12 @@ makeLenses 'RefChanHeadBlockSmall
|
||||||
type ForRefChans e = ( Serialise ( PubKey 'Sign (Encryption e))
|
type ForRefChans e = ( Serialise ( PubKey 'Sign (Encryption e))
|
||||||
, Pretty (AsBase58 (PubKey 'Sign (Encryption e)))
|
, Pretty (AsBase58 (PubKey 'Sign (Encryption e)))
|
||||||
, FromStringMaybe (PubKey 'Sign (Encryption e))
|
, FromStringMaybe (PubKey 'Sign (Encryption e))
|
||||||
|
, Serialise (Signature (Encryption e))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
instance ForRefChans e => Serialise (RefChanHeadBlock e)
|
||||||
|
instance ForRefChans e => Serialise (SignedBox p e)
|
||||||
|
|
||||||
-- блок головы может быть довольно большой.
|
-- блок головы может быть довольно большой.
|
||||||
-- поэтому посылаем его, как merkle tree
|
-- поэтому посылаем его, как merkle tree
|
||||||
newtype RefChanHeadBlockTran e =
|
newtype RefChanHeadBlockTran e =
|
||||||
|
@ -116,6 +119,19 @@ makeSignedBox pk sk msg = SignedBox @p @e pk bs sign
|
||||||
bs = LBS.toStrict (serialise msg)
|
bs = LBS.toStrict (serialise msg)
|
||||||
sign = makeSign @(Encryption e) sk bs
|
sign = makeSign @(Encryption e) sk bs
|
||||||
|
|
||||||
|
unboxSignedBox :: forall p e . (Serialise p, ForRefChans e, Signatures (Encryption e))
|
||||||
|
=> LBS.ByteString
|
||||||
|
-> Maybe p
|
||||||
|
|
||||||
|
unboxSignedBox bs = runIdentity $ runMaybeT do
|
||||||
|
|
||||||
|
(SignedBox pk bs sign) <- MaybeT $ pure
|
||||||
|
$ deserialiseOrFail @(SignedBox p e) bs
|
||||||
|
& either (pure Nothing) Just
|
||||||
|
|
||||||
|
guard $ verifySign @(Encryption e) pk sign bs
|
||||||
|
|
||||||
|
MaybeT $ pure $ deserialiseOrFail @p (LBS.fromStrict bs) & either (const Nothing) Just
|
||||||
|
|
||||||
instance ForRefChans e => FromStringMaybe (RefChanHeadBlock e) where
|
instance ForRefChans e => FromStringMaybe (RefChanHeadBlock e) where
|
||||||
fromStringMay str = RefChanHeadBlockSmall <$> version
|
fromStringMay str = RefChanHeadBlockSmall <$> version
|
||||||
|
|
|
@ -48,6 +48,7 @@ import RefLog (reflogWorker)
|
||||||
import HttpWorker
|
import HttpWorker
|
||||||
import ProxyMessaging
|
import ProxyMessaging
|
||||||
import PeerMeta
|
import PeerMeta
|
||||||
|
import CLI.RefChan
|
||||||
|
|
||||||
import Codec.Serialise
|
import Codec.Serialise
|
||||||
-- import Control.Concurrent.Async
|
-- import Control.Concurrent.Async
|
||||||
|
@ -244,6 +245,7 @@ runCLI = join . customExecParser (prefs showHelpOnError) $
|
||||||
<> command "ping" (info pPing (progDesc "ping another peer"))
|
<> command "ping" (info pPing (progDesc "ping another peer"))
|
||||||
<> command "fetch" (info pFetch (progDesc "fetch block"))
|
<> command "fetch" (info pFetch (progDesc "fetch block"))
|
||||||
<> command "reflog" (info pRefLog (progDesc "reflog commands"))
|
<> command "reflog" (info pRefLog (progDesc "reflog commands"))
|
||||||
|
<> command "refchan" (info pRefChan (progDesc "refchan commands"))
|
||||||
<> command "peers" (info pPeers (progDesc "show known peers"))
|
<> command "peers" (info pPeers (progDesc "show known peers"))
|
||||||
<> command "log" (info pLog (progDesc "set logging level"))
|
<> command "log" (info pLog (progDesc "set logging level"))
|
||||||
)
|
)
|
||||||
|
@ -335,7 +337,6 @@ runCLI = join . customExecParser (prefs showHelpOnError) $
|
||||||
setLogging @TRACE tracePrefix
|
setLogging @TRACE tracePrefix
|
||||||
trace "pRefLogSend"
|
trace "pRefLogSend"
|
||||||
s <- BS.readFile kr
|
s <- BS.readFile kr
|
||||||
-- FIXME: UDP is weird here
|
|
||||||
creds <- pure (parseCredentials @(Encryption L4Proto) (AsCredFile s)) `orDie` "bad keyring file"
|
creds <- pure (parseCredentials @(Encryption L4Proto) (AsCredFile s)) `orDie` "bad keyring file"
|
||||||
bs <- BS.take defChunkSize <$> BS.hGetContents stdin
|
bs <- BS.take defChunkSize <$> BS.hGetContents stdin
|
||||||
let pubk = view peerSignPk creds
|
let pubk = view peerSignPk creds
|
||||||
|
|
|
@ -131,6 +131,7 @@ executable hbs2-peer
|
||||||
, HttpWorker
|
, HttpWorker
|
||||||
, Brains
|
, Brains
|
||||||
, ProxyMessaging
|
, ProxyMessaging
|
||||||
|
, CLI.RefChan
|
||||||
|
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
build-depends: base
|
build-depends: base
|
||||||
|
|
Loading…
Reference in New Issue