4b82 中文文档教程

发布于 10年前 浏览 29 项目主页 更新于 3年前

4b82 - Continuity Trustcenter Framework

Based on GIT and Merkle Tree

附言。 4B82 是 GIT 空树“树 0\0”的哈希值的前四个符号 4b825dc642cb6eb9a060e54bf8d69288fbee4904

4B82 Project Key Technical Details

该项目的目标是允许一种直接而稳健的方式来建立抽象的、可证明的不可变数字事件序列.

目前实现这一目标的现有方法依赖于高度专业化的软件,对计算要求很高,或两者兼而有之。

我们决定使用 GIT 的架构框架作为实现此功能的核心,因为它具有通用性、健壮性、强大的反腐败保护措施以及不言而喻的灵活性。

严格的线性是通过利用所有类似 git 的解决方案的典型散列功能同时避免分支功能来实现的,并且以最小化典型 git 对象行为的不必要(为了我们的目的)开销的方式完成(但不损害形式的完整性涉及的 git 结构)。

4b82.com 阅读更多关于 4b82 Continuity Trustcenter Framework 的

How to Use it?

信息 初始化一个空的 git 存储库:

mkdir git-repo && cd git-repo
git init
cd ..

创建新的 node.js 项目:

mkdir 4b82-server && cd 4b82-server
npm init

添加 4b82 代码来自 npm:

npm install 4b82 --save

现在,您可以使用 4b82 函数并制作您自己的 4b82 服务器。

API Functions

注意:所有的回调函数都是function (err, result)或者function (err)。 如果发生错误,err 对象将被传递给回调函数。 否则,err 对象为 null 并且 result 对象将被传递给回调函数(如果 result 存在)。

Initialization

首先,需要初始化应用程序。

在初始化期间,需要传递一个配置对象。 目前,这个对象很简单,包含一个 git 字段。 该字段是一个带有 path 字段的对象,该字段存储 GIT 存储库的路径。 例如:

Configuration Object

{
    git: {
        path: 'path-to-git'
    }
}

Application Initialization

function init (conf)

ArgumentsDescription
confConfiguration object (see above)

Exclusive Access

在对 GIT 存储库进行任何更改之前,您必须在应用程序级别获得对 GIT 存储库的独占访问权限。

重要:请不要忘记调用 releaseAccess() 并在操作结束时释放对存储库的独占访问权限。

重要:仅在应用程序逻辑级别而非系统级别提供独占访问权限。

Obtain the Exclusive Access

function getAccess(回调)

ArgumentsDescription
callback (err)Callback function that calls immediately after receiving
the exclusive access to the GIT repository

Release the Exclusive Access

function releaseAccess()

ArgumentsDescription
noneReleases the exclusive access to the GIT repository

Adding and Reading Commits

Add a Commit to the Repository

function addCommit(消息,作者,提交者,回调)

ArgumentsDescription
messageCommit message
authorCommit author
committerCommitter (your system)
callback (err, commit)Callback function that receives commit object after adding or error

Get the Recently Added Commit

function getRecentCommit(回调)< /code>

ArgumentsDescription
callback (err, commit)Callback function that receives commit object after adding or error.
If there is no commits, null is returned.

Get the Commit With Hash Value

function getCommit (hash, callback)

ArgumentsDescription
hashThe hash value for the desired commit
callback (err, commit)Callback function that receives commit object after adding or error.
If there is no commits, null is returned.

Display the Commit Data

function prettyPrint (commit) - 显示有关提交

ArgumentsDescription
commitCommit object returned by addCommit, getRecentCommit or getCommit functions

Examples

的信息一个简单的应用程序,将提交添加到我们新的 4b82 git 存储库:

var _4b82 = require('4b82');

var config = {
    git: { path: '~/git-path/' } // Path to git repository
}

// Initialize 4b82
_4b82.init(config, function (err) {
    if (err) return console.error(err);

    // Get exclusive access to GIT
    _4b82.getAccess(function () {

        // Add commit
        _4b82.addCommit('test commit', 'me <me@localhost>', 'me <me@localhost>',
                function (err, commit) {

            if (err) {
                _4b82.releaseAccess();
                return console.error(err);
            }

            // Print commit data
            _4b82.prettyPrint(commit);

            // Release access
            _4b82.releaseAccess();

        });
    });
});

当您运行此应用程序将新提交添加到 4b82 git 存储库并打印 commit hashdatadeflated bytes

要获得特定的提交,请使用 getCommit 函数:

// Initialize 4b82
_4b82.init(config, function (err) {
    if (err) return console.error(err);

    // Get commit data
    _4b82.getCommit(hash, function (err, commit) {
        if (err) return console.error(err);

        // Print commit data
        _4b82.prettyPrint(commit);

    })
});

此函数返回提交对象(带有标记字段)。

commit 包含完整的 git commit 数据,你可以为作者、提交者等解析它

tag 字段用于向后导航(阅读更多关于 向后导航)。


就是这样。

4b82 - Continuity Trustcenter Framework

Based on GIT and Merkle Tree

ps. 4B82 is the first four symbols of the hash value for the GIT empty-tree "tree 0\0" 4b825dc642cb6eb9a060e54bf8d69288fbee4904

4B82 Project Key Technical Details

The goal of this project is to allow a straightforward and robust way to establish abstract, provably immutable sequences of digital events.

Currently existing methods for attaining this rely on highly specialized software, are computationally demanding, or both.

We have decided to use GIT’s architectural framework as the core implementing this functionality because of its versatility, robustness, strong safeguards against corruption, as well as its self-evidential flexibility.

Strict linearity was achieved by leveraging hash functionality typical to all git-like solutions while eschewing branching functionality, and was done in a manner that minimizes unnecessary (for our purposes) overhead of typical git object behaviors (but does not compromise the formal integrity of the git structures involved).

Read more about 4b82 Continuity Trustcenter Framework at 4b82.com

How to Use it?

Initialize an empty git repository:

mkdir git-repo && cd git-repo
git init
cd ..

Create the new node.js project:

mkdir 4b82-server && cd 4b82-server
npm init

Add 4b82 code from npm:

npm install 4b82 --save

Now, you can use 4b82 functions and make your own 4b82 server.

API Functions

Note: all callback functions are function (err, result) or function (err). if an error occurs then err object will be passed to callback function. Otherwise, err object is null and result object will be passed to the callback function (if result is exists).

Initialization

First, it is necessary to initialize the application.

During initialization, it is necessary to pass a configuration object. Currently, this object is simple and includes a git field. This field is an object with the path field which stores the path to the GIT repository. For example:

Configuration Object

{
    git: {
        path: 'path-to-git'
    }
}

Application Initialization

function init (conf)

ArgumentsDescription
confConfiguration object (see above)

Exclusive Access

Before you make any changes to the GIT-repository, you must obtain an exclusive access to GIT-repository at the application level.

Important: please, do not forget to call releaseAccess() and to release exclusive access to the repository at the end of the operation.

Important: exclusive access is provided only at the application logic level, not the system level.

Obtain the Exclusive Access

function getAccess (callback)

ArgumentsDescription
callback (err)Callback function that calls immediately after receiving
the exclusive access to the GIT repository

Release the Exclusive Access

function releaseAccess ()

ArgumentsDescription
noneReleases the exclusive access to the GIT repository

Adding and Reading Commits

Add a Commit to the Repository

function addCommit (message, author, committer, callback)

ArgumentsDescription
messageCommit message
authorCommit author
committerCommitter (your system)
callback (err, commit)Callback function that receives commit object after adding or error

Get the Recently Added Commit

function getRecentCommit (callback)

ArgumentsDescription
callback (err, commit)Callback function that receives commit object after adding or error.
If there is no commits, null is returned.

Get the Commit With Hash Value

function getCommit (hash, callback)

ArgumentsDescription
hashThe hash value for the desired commit
callback (err, commit)Callback function that receives commit object after adding or error.
If there is no commits, null is returned.

Display the Commit Data

function prettyPrint (commit) - show information about commit

ArgumentsDescription
commitCommit object returned by addCommit, getRecentCommit or getCommit functions

Examples

A simple application that adds commit to our fresh 4b82 git repository:

var _4b82 = require('4b82');

var config = {
    git: { path: '~/git-path/' } // Path to git repository
}

// Initialize 4b82
_4b82.init(config, function (err) {
    if (err) return console.error(err);

    // Get exclusive access to GIT
    _4b82.getAccess(function () {

        // Add commit
        _4b82.addCommit('test commit', 'me <me@localhost>', 'me <me@localhost>',
                function (err, commit) {

            if (err) {
                _4b82.releaseAccess();
                return console.error(err);
            }

            // Print commit data
            _4b82.prettyPrint(commit);

            // Release access
            _4b82.releaseAccess();

        });
    });
});

When you run this application it adds new commit to 4b82 git repository and prints the commit hash, data and deflated bytes.

To get specific commit use getCommit function:

// Initialize 4b82
_4b82.init(config, function (err) {
    if (err) return console.error(err);

    // Get commit data
    _4b82.getCommit(hash, function (err, commit) {
        if (err) return console.error(err);

        // Print commit data
        _4b82.prettyPrint(commit);

    })
});

This function returns commit object (with tag field).

commit contains whole git commit data, you can parse it for author, committer, e.t.c.

tag field uses for backward navigation (read more about backward navigation).


That's all.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文