This commit is contained in:
Dmitry Zuikov 2024-04-13 07:22:14 +03:00
parent ba7cc35bbc
commit e405142b8c
6 changed files with 115 additions and 21 deletions

View File

@ -39,6 +39,7 @@ commands =
hsubparser ( command "export" (info pExport (progDesc "export repo to hbs2-git")) hsubparser ( command "export" (info pExport (progDesc "export repo to hbs2-git"))
<> command "import" (info pImport (progDesc "import repo from reflog")) <> command "import" (info pImport (progDesc "import repo from reflog"))
<> command "key" (info pKey (progDesc "key management")) <> command "key" (info pKey (progDesc "key management"))
<> command "track" (info pTrack (progDesc "track tools"))
<> command "tools" (info pTools (progDesc "misc tools")) <> command "tools" (info pTools (progDesc "misc tools"))
) )
@ -46,6 +47,8 @@ commands =
pRefLogId :: ReadM RefLogId pRefLogId :: ReadM RefLogId
pRefLogId = maybeReader (fromStringMay @RefLogId) pRefLogId = maybeReader (fromStringMay @RefLogId)
pRefChanId :: ReadM GitRefChanId
pRefChanId = maybeReader (fromStringMay @GitRefChanId)
pLwwKey :: ReadM (LWWRefKey 'HBS2Basic) pLwwKey :: ReadM (LWWRefKey 'HBS2Basic)
pLwwKey = maybeReader fromStringMay pLwwKey = maybeReader fromStringMay
@ -205,6 +208,18 @@ pKeyUpdate = do
Nothing -> liftIO $ putStrLn "not added" >> exitFailure Nothing -> liftIO $ putStrLn "not added" >> exitFailure
Just x -> liftIO $ print $ pretty x Just x -> liftIO $ print $ pretty x
pTrack :: GitPerks m => Parser (GitCLI m ())
pTrack = hsubparser ( command "send-repo-notify" (info pSendRepoNotify (progDesc "sends repository notification"))
)
pSendRepoNotify :: GitPerks m => Parser (GitCLI m ())
pSendRepoNotify = do
notifyChan <- argument pRefChanId (metavar "CHANNEL-KEY")
pure do
notice "JOPA"
pure ()
main :: IO () main :: IO ()
main = do main = do
(o, action) <- customExecParser (prefs showHelpOnError) $ (o, action) <- customExecParser (prefs showHelpOnError) $

View File

@ -17,6 +17,7 @@ module HBS2.Git.Client.Prelude
, module HBS2.Peer.Proto.LWWRef , module HBS2.Peer.Proto.LWWRef
, module HBS2.Peer.RPC.API.Peer , module HBS2.Peer.RPC.API.Peer
, module HBS2.Peer.RPC.API.RefLog , module HBS2.Peer.RPC.API.RefLog
, module HBS2.Peer.RPC.API.RefChan
, module HBS2.Peer.RPC.API.LWWRef , module HBS2.Peer.RPC.API.LWWRef
, module HBS2.Peer.RPC.API.Storage , module HBS2.Peer.RPC.API.Storage
, module HBS2.Peer.RPC.Client.StorageClient , module HBS2.Peer.RPC.Client.StorageClient
@ -33,6 +34,7 @@ module HBS2.Git.Client.Prelude
, getSocketName , getSocketName
, formatRef , formatRef
, deserialiseOrFail , deserialiseOrFail
, GitRefChanId
) where ) where
import HBS2.Prelude.Plated hiding (at) import HBS2.Prelude.Plated hiding (at)
@ -56,6 +58,7 @@ import HBS2.Net.Proto.Service
import HBS2.Peer.Proto.LWWRef import HBS2.Peer.Proto.LWWRef
import HBS2.Peer.RPC.API.Peer import HBS2.Peer.RPC.API.Peer
import HBS2.Peer.RPC.API.RefLog import HBS2.Peer.RPC.API.RefLog
import HBS2.Peer.RPC.API.RefChan
import HBS2.Peer.RPC.API.LWWRef import HBS2.Peer.RPC.API.LWWRef
import HBS2.Peer.RPC.API.Storage import HBS2.Peer.RPC.API.Storage
import HBS2.Peer.RPC.Client.StorageClient import HBS2.Peer.RPC.Client.StorageClient
@ -73,6 +76,9 @@ import System.Process.Typed
import Lens.Micro.Platform import Lens.Micro.Platform
import Codec.Serialise import Codec.Serialise
-- FIXME: subject-to-change-signature
type GitRefChanId = RefChanId L4Proto
data RPCNotFoundError = RPCNotFoundError data RPCNotFoundError = RPCNotFoundError
deriving stock (Show,Typeable) deriving stock (Show,Typeable)

View File

@ -161,6 +161,15 @@ makeTx sto rewrite r puk findSk rh prev lbss = do
let meRef = HashRef me let meRef = HashRef me
-- FIXME: ASAP-race-condition-on-seq-ref
-- При разборе транзакции, если по какой-то причине
-- голова сразу не подъезжает, то не подъедет уже никогда,
-- и бранчи не приедут (Import).
--
-- Возможные решения: запатчить процедуру импорта (1)
-- Добавить ссылкун а RepoHead в блок, где приезжают
-- пулы
-- TODO: post-real-rank-for-tx -- TODO: post-real-rank-for-tx
let tx = SequentialRef r (AnnotatedHashRef (Just headRef) meRef) let tx = SequentialRef r (AnnotatedHashRef (Just headRef) meRef)
& serialise & serialise

View File

@ -1,4 +1,5 @@
{-# Language UndecidableInstances #-} {-# Language UndecidableInstances #-}
{-# Language AllowAmbiguousTypes #-}
module HBS2.Git.Data.Tx.Index where module HBS2.Git.Data.Tx.Index where
import HBS2.Git.Client.Prelude import HBS2.Git.Client.Prelude
@ -6,7 +7,8 @@ import HBS2.Data.Types.Refs
import HBS2.Data.Types.SignedBox import HBS2.Data.Types.SignedBox
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import Data.ByteString.Lazy qualified as LBS
import Data.Coerce
-- | -- |
-- Module : HBS2.Git.Data.Tx.Index -- Module : HBS2.Git.Data.Tx.Index
@ -43,21 +45,27 @@ instance ForGitIndex s => Serialise (GitRepoAnnounce s)
data NotifyCredentials s = data NotifyCredentials s =
NotifyCredentials (PubKey 'Sign s) (PrivKey 'Sign s) NotifyCredentials
{ notifyPk :: PubKey 'Sign s
data RepoCredentials s = , notifySk :: PrivKey 'Sign s
RepoCredentials
{ rcPubKey :: PubKey 'Sign s
, rcSeckey :: PrivKey 'Sign s
} }
-- | makes notification tx
-- | it is signed by lwwref private key in order to proove authorship
-- | and signed with published notification private key in order
-- | to publish tx via rpc
makeNotificationTx :: forall s m . (Monad m, ForGitIndex s) makeNotificationTx :: forall s m . (Monad m, ForGitIndex s)
=> NotifyCredentials s => NotifyCredentials s
-> RepoCredentials s -> LWWRefKey s
-> ( PubKey 'Sign s -> m (Maybe (PrivKey 'Sign s) ) )
-> Maybe (RepoForkInfo s) -> Maybe (RepoForkInfo s)
-> m ByteString -> m (Maybe (SignedBox ByteString s))
makeNotificationTx ncred repocred forkInfo = do makeNotificationTx ncred lww klook forkInfo = runMaybeT do
-- makeSignedBox @e (LBS.toStrict $ serialise tx) let annData = GitRepoAnnounceData @s lww forkInfo
let annData = GitRepoAnnounceData @s (LWWRefKey $ rcPubKey repocred) let lwpk = coerce lww :: PubKey 'Sign s
undefined lwsk <- MaybeT $ klook lwpk
let repoAnn = makeSignedBox @s lwpk lwsk (LBS.toStrict $ serialise annData)
pure $ makeSignedBox @s (notifyPk ncred) (notifySk ncred) (LBS.toStrict $ serialise repoAnn)

View File

@ -172,6 +172,21 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_8": {
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"haskell-flake-utils": { "haskell-flake-utils": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2" "flake-utils": "flake-utils_2"
@ -268,6 +283,24 @@
"inputs": { "inputs": {
"flake-utils": "flake-utils_7" "flake-utils": "flake-utils_7"
}, },
"locked": {
"lastModified": 1698938553,
"narHash": "sha256-oXpTKXioqFbl2mhhvpJIAvgNd+wYyv4ekI+YnJHEJ6s=",
"owner": "ivanovs-4",
"repo": "haskell-flake-utils",
"rev": "19b273b5dc401a0a565e7f75cf50a593871b80c9",
"type": "github"
},
"original": {
"owner": "ivanovs-4",
"repo": "haskell-flake-utils",
"type": "github"
}
},
"haskell-flake-utils_7": {
"inputs": {
"flake-utils": "flake-utils_8"
},
"locked": { "locked": {
"lastModified": 1672412555, "lastModified": 1672412555,
"narHash": "sha256-Kaa8F7nQFR3KuS6Y9WRUxeJeZlp6CCubyrRfmiEsW4k=", "narHash": "sha256-Kaa8F7nQFR3KuS6Y9WRUxeJeZlp6CCubyrRfmiEsW4k=",
@ -288,6 +321,7 @@
"fixme": "fixme", "fixme": "fixme",
"haskell-flake-utils": "haskell-flake-utils_4", "haskell-flake-utils": "haskell-flake-utils_4",
"hspup": "hspup", "hspup": "hspup",
"lsm": "lsm",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
@ -295,16 +329,16 @@
"suckless-conf": "suckless-conf_2" "suckless-conf": "suckless-conf_2"
}, },
"locked": { "locked": {
"lastModified": 1710646368, "lastModified": 1711190148,
"narHash": "sha256-0ayUFjOSX4UqSRBbLJeqPMBAn+qSAlFRoICVABliF80=", "narHash": "sha256-XnvjD8yvSrSTMmsy3fE7chVg1oDBamMaWkEZ0lJ8sHU=",
"ref": "lwwrepo", "ref": "dev-0.24.2",
"rev": "16b5b6220a4be96e30c65f34d631445c28676feb", "rev": "37618a32bb0ae5bfa8b8380c6537638b1f5d412d",
"revCount": 1002, "revCount": 983,
"type": "git", "type": "git",
"url": "http://git.hbs2/BTThPdHKF8XnEq4m6wzbKHKA6geLFK4ydYhBXAqBdHSP" "url": "http://git.hbs2/BTThPdHKF8XnEq4m6wzbKHKA6geLFK4ydYhBXAqBdHSP"
}, },
"original": { "original": {
"ref": "lwwrepo", "ref": "dev-0.24.2",
"type": "git", "type": "git",
"url": "http://git.hbs2/BTThPdHKF8XnEq4m6wzbKHKA6geLFK4ydYhBXAqBdHSP" "url": "http://git.hbs2/BTThPdHKF8XnEq4m6wzbKHKA6geLFK4ydYhBXAqBdHSP"
} }
@ -351,6 +385,28 @@
"type": "github" "type": "github"
} }
}, },
"lsm": {
"inputs": {
"haskell-flake-utils": "haskell-flake-utils_6",
"nixpkgs": [
"hbs2",
"nixpkgs"
]
},
"locked": {
"lastModified": 1711033804,
"narHash": "sha256-z9cb5yuWfuZmGukxsZebXhc6KUZoPVT60oXxQ6j6ML8=",
"ref": "refs/heads/master",
"rev": "0e8286a43da5b9e54c4f3ecdb994173fe77351db",
"revCount": 26,
"type": "git",
"url": "https://git.hbs2.net/5BCaH95cWsVKBmWaDNLWQr2umxzzT5kqRRKNTm2J15Ls"
},
"original": {
"type": "git",
"url": "https://git.hbs2.net/5BCaH95cWsVKBmWaDNLWQr2umxzzT5kqRRKNTm2J15Ls"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1685566663, "lastModified": 1685566663,
@ -433,7 +489,7 @@
}, },
"suckless-conf_2": { "suckless-conf_2": {
"inputs": { "inputs": {
"haskell-flake-utils": "haskell-flake-utils_6", "haskell-flake-utils": "haskell-flake-utils_7",
"nixpkgs": [ "nixpkgs": [
"hbs2", "hbs2",
"nixpkgs" "nixpkgs"

View File

@ -7,7 +7,7 @@
extra-container.url = "github:erikarvstedt/extra-container"; extra-container.url = "github:erikarvstedt/extra-container";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
hbs2.url = hbs2.url =
"git+http://git.hbs2/BTThPdHKF8XnEq4m6wzbKHKA6geLFK4ydYhBXAqBdHSP?ref=lwwrepo"; "git+http://git.hbs2/BTThPdHKF8XnEq4m6wzbKHKA6geLFK4ydYhBXAqBdHSP?ref=dev-0.24.2";
hbs2.inputs.nixpkgs.follows = "nixpkgs"; hbs2.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager"; home-manager.url = "github:nix-community/home-manager";