Skip to content

Commit

Permalink
Release 3.0.0 (bittorrent#442)
Browse files Browse the repository at this point in the history
* feat[cheque]: add command about batch cashing cheque

* ci: add test command

* feat: encrypt support symmetrical encryption

* feat: implementation btip-73

* feat: use last connect peer

* feat: refactor use last conn peer

* feat: use last conn to boot

* doc: update annotations

* fix: need conn peer filer error

* feat: update config dependency for updating bootstrap

* feat: get peer addr from addrbook

* feat: add try duration from last conn

* feat: change go routine limit to peers size on do conn

* fix: judge if from option is empty

* fix: check if pass is empty

* feat: give a more friendly hint

* fix: get local data when from is exactly local node

* feat: add a timeout when get an encrypted cid

* fix: status report list should not return a nil

* feat: update dashboard cid and version

* feat: update readme

* feat: update readme

* feat: update readme

* feat: udpate some expressions in readme

* feat: update latest cid

---------

Co-authored-by: cody <[email protected]>
Co-authored-by: cody <[email protected]>
Co-authored-by: Cody <[email protected]>
  • Loading branch information
4 people authored Jun 18, 2024
1 parent 9fdd194 commit 83008eb
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 73 deletions.
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
# go-btfs

## What is BTFS 2.0?
## What is BTFS 3.0?

BitTorrent File System (BTFS) is a next-generation file sharing protocol in the BitTorrent ecosystem. Current mainstream public blockchains mostly focus on computational tasks but lack cost-effective, scalable, and high-performing file storage and sharing solutions.
BTFS, as an innovative force in the BitTorrent ecosystem, has not only accelerated the development of distributed file sharing technology, but also taken a leading position in the field of DePIN. DePIN - which stands for Decentralized Physical Infrastructure Network - encourages network participants to jointly invest resources to deploy and maintain a more stable and efficient network infrastructure through a token reward mechanism. Current mainstream public blockchains mostly focus on computational tasks but lack cost-effective, scalable, and high-performing file storage and sharing solutions.

These are exactly what BTFS aims to clear up. Besides, underpinned by BTTC, BTFS enables cross-chain connectivity and multi-channel payments, making itself a more convenient choice. The intgration of BTFS, BitTorrent, and the BTTC network will boost DApp developers' efficiency in serving a wider market.
These are exactly what BTFS aims to clear up. Additionally, underpinned by BTTC, BTFS enables cross-chain connectivity and multi-channel payments, making it a more convenient choice. The integration of BTFS, BitTorrent, and the BTTC network will boost DApp developers' efficiency in serving a wider market.

* The [documentation](https://docs.btfs.io/) walks developers through BTFS 2.0 setup, usage, and API references.
* Please join the BTFS community at [discord](https://discord.com/invite/tJ4fz6C6rw).
* The [documentation](https://docs.btfs.io/) walks developers through BTFS 3.0 setup, usage, and API references.
* Please join the BTFS community on [Discord](https://discord.com/invite/tJ4fz6C6rw).

## BTFS 2.0 Architecture Diagram
Decentralized Physical Infrastructure Networks (DePINs), catalyzed by advancements in blockchain technology, aim to revolutionize network architecture by shifting away from centralized infrastructure. This transformation is made possible by the evolution of blockchain infrastructure and advancements in cryptography, enabling a global collaborative effort to establish open and permissionless infrastructure. This approach disrupts traditional infrastructure models, which are typically dominated by major corporations.
The BitTorrent File System (BTFS), an open and distributed file storage system, aligns perfectly with the goals of DePIN.

BTFS represents the next generation of decentralized file storage systems powered by blockchain technology and peer-to-peer transmission. It allows users to store files across multiple global nodes, enhancing file security and reliability while facilitating faster access and transfer. This setup provides an effortless file management and sharing experience. Additionally, it incorporates key features from the BitTorrent Chain (BTTC) network, such as cross-chain connectivity and multichannel payment options.

As a stellar player in the DePIN space, BTFS v3.0 boasts the following advantages:

* Decentralized Storage: BTFS has achieved global decentralized file storage through its distributed network. Unlike centralized storage on single servers, this method significantly increases data redundancy and reduces the risk of data loss. The BTFS v3.0 update includes enhancements such as symmetric encryption for secure data transmission and new features like Keystore files for managing BTFS nodes.
* Enhanced Security: The decentralized nature of data storage makes it difficult for attackers to target all nodes simultaneously, greatly improving the system's overall security.
* Censorship-Proof: The inherent nature of a decentralized storage system makes it extremely difficult for any single organization to censor or block content, ensuring the free flow of data.
* Seamless Integration Into the BitTorrent Ecosystem: The seamless integration of BTFS with the BitTorrent ecosystem allows users to freely access and share files, as well as facilitates cross-chain transactions and payments via BTTC.
* User-friendly API and Visual Interface: A newly updated BTFS website offers a user-friendly API and visual interface, featuring detailed road maps on Storage Reward halving and various other modules.
* Transparent Market Mechanism: The market mechanism within BTFS ensures complete transparency in storage and payment processes, providing users with maximum visibility into their data.
* Encryption Technology: By leveraging advanced encryption technologies, BTFS enhances data privacy and security, ensuring data integrity and preventing unauthorized access during transmission and storage.

In addition to these features, the upgraded BTFS v3.0 introduces a crucial model update—the Reward Halving. As the BTFS network and its user base grow, the reward halving is likely to contribute to the reliable and sustainable growth of the entire ecosystem.

BTFS, a leading project in the space of DePIN, is committed to advancing and enhancing the decentralized physical infrastructure network. The improved token economics of BTFS not only align with the vision of DePIN but also lay a solid foundation for the growth of decentralized networks. As technology and community evolve, BTFS is poised to play an increasingly significant role in the decentralized world.

## BTFS 3.0 Architecture Diagram

![Architecture Diagram](https://files.readme.io/a21e9fb--min.png)

## Table of Contents
- [go-btfs](#go-btfs)
- [What is BTFS 2.0?](#what-is-btfs-20)
- [BTFS 2.0 Architecture Diagram](#btfs-20-architecture-diagram)
- [What is BTFS 3.0?](#what-is-btfs-30)
- [BTFS 3.0 Architecture Diagram](#btfs-30-architecture-diagram)
- [Table of Contents](#table-of-contents)
- [Faucet](#faucet)
- [Install BTFS](#install-btfs)
Expand All @@ -39,7 +58,7 @@ These are exactly what BTFS aims to clear up. Besides, underpinned by BTTC, BTFS

## Faucet

In order to ensure the normal use of btfs 2.0 testnet, you need to apply for BTT at BTTC testnet, which is obtained [**here**](https://testfaucet.bt.io/#/).
In order to ensure the normal use of btfs 3.0 testnet, you need to apply for BTT at BTTC testnet, which is obtained [**here**](https://testfaucet.bt.io/#/).

## Install BTFS

Expand Down Expand Up @@ -82,7 +101,7 @@ Specify the chain for btfs to run by `--chain-id`, the chainid of the test netwo
```
$ btfs daemon --chain-id 1029
Initializing daemon...
go-btfs version: 2.0
go-btfs version: 3.0
Repo version: 10
System version: amd64/darwin
Golang version: go1.16.5
Expand Down
28 changes: 28 additions & 0 deletions cmd/btfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand All @@ -21,6 +22,8 @@ import (
"github.com/bittorrent/go-btfs/core/commands"
"github.com/bittorrent/go-btfs/namesys"
fsrepo "github.com/bittorrent/go-btfs/repo/fsrepo"
"github.com/ethereum/go-ethereum/accounts/keystore"
ethCrypto "github.com/ethereum/go-ethereum/crypto"

cmds "github.com/bittorrent/go-btfs-cmds"
config "github.com/bittorrent/go-btfs-config"
Expand All @@ -33,6 +36,8 @@ const (
profileOptionName = "profile"
keyTypeDefault = "BIP39"
keyTypeOptionName = "key"
keyPathOptionName = "keypath"
passOptionName = "pass"
importKeyOptionName = "import"
rmOnUnpinOptionName = "rm-on-unpin"
seedOptionName = "seed"
Expand Down Expand Up @@ -70,6 +75,8 @@ environment variable:
cmds.BoolOption(emptyRepoOptionName, "e", "Don't add and pin help files to the local storage."),
cmds.StringOption(profileOptionName, "p", "Apply profile settings to config. Multiple profiles can be separated by ','"),
cmds.StringOption(keyTypeOptionName, "k", "Key generation algorithm, e.g. RSA, Ed25519, Secp256k1, ECDSA, BIP39. By default is BIP39"),
cmds.StringOption(keyPathOptionName, "kp", "Keystore file path when key type is keystore"),
cmds.StringOption(passOptionName, "Keystore file password when key type is keystore"),
cmds.StringOption(importKeyOptionName, "i", "Import TRON private key to generate btfs PeerID."),
cmds.BoolOption(rmOnUnpinOptionName, "r", "Remove unpinned files.").WithDefault(false),
cmds.StringOption(seedOptionName, "s", "Import seed phrase"),
Expand Down Expand Up @@ -139,10 +146,31 @@ environment variable:
keyType, _ := req.Options[keyTypeOptionName].(string)
seedPhrase, _ := req.Options[seedOptionName].(string)
simpleModeIn, _ := req.Options[simpleMode].(bool)
keyPath, _ := req.Options[keyPathOptionName].(string)
keyPass, _ := req.Options[passOptionName].(string)
/*
password, _ := req.Options[passWordOptionName].(string)
passwordFile, _ := req.Options[passwordFileoptionName].(string)
*/
if keyType == "keystore" {
if keyPath == "" || keyPass == "" {
return fmt.Errorf("keypath or pass option should not be empty when key type is keystore")
}
file, err := os.Open(keyPath)
if err != nil {
return err
}
jsonBytes, err := io.ReadAll(file)
if err != nil {
return err
}
key, err := keystore.DecryptKey(jsonBytes, keyPass)
if err != nil {
return err
}
importKey = hex.EncodeToString(ethCrypto.FromECDSA(key.PrivateKey))
keyType = "Secp256k1"
}
backupPath, ok := req.Options[recoveryOptionName].(string)
if ok {
btfsPath := env.(*oldcmds.Context).ConfigRoot
Expand Down
3 changes: 0 additions & 3 deletions core/commands/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func Tar(src, dst string, excludePath []string) (err error) {
}
hdr.Name = rel

// 写入文件信息
if err = tw.WriteHeader(hdr); err != nil {
return err
}
Expand All @@ -185,7 +184,6 @@ func Tar(src, dst string, excludePath []string) (err error) {
}
defer fr.Close()

// copy 文件数据到 tw
_, err = io.Copy(tw, fr)
if err != nil {
return err
Expand Down Expand Up @@ -232,7 +230,6 @@ func UnTar(src, dst string) (err error) {
return err
}
defer fw.Close()
// 写文件
_, err = io.Copy(fw, tr)
if err != nil {
return err
Expand Down
53 changes: 51 additions & 2 deletions core/commands/cheque/cheque.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package cheque
import (
"errors"
"fmt"
"github.com/bittorrent/go-btfs/chain/tokencfg"
"github.com/bittorrent/go-btfs/utils"
"io"
"math/big"
"time"

"github.com/bittorrent/go-btfs/chain/tokencfg"
"github.com/bittorrent/go-btfs/utils"

cmds "github.com/bittorrent/go-btfs-cmds"
"github.com/bittorrent/go-btfs/chain"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -80,6 +81,7 @@ Vault services include issue cheque to peer, receive cheque and store operations
},
Subcommands: map[string]*cmds.Command{
"cash": CashChequeCmd,
"batch-cash": BatchCashChequeCmd,
"cashstatus": ChequeCashStatusCmd,
"cashlist": ChequeCashListCmd,
"price": StorePriceCmd,
Expand Down Expand Up @@ -257,3 +259,50 @@ var CashChequeCmd = &cmds.Command{
}),
},
}

var BatchCashChequeCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Batch cash the cheques by peerIDs.",
},
Arguments: []cmds.Argument{
cmds.StringArg("peer-ids", true, true, "Peer id tobe cashed."),
},
Options: []cmds.Option{
cmds.StringOption(tokencfg.TokenTypeName, "tk", "file storage with token type,default WBTT, other TRX/USDD/USDT.").WithDefault("WBTT"),
},
RunTimeout: 5 * time.Minute,
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
err := utils.CheckSimpleMode(env)
if err != nil {
return err
}

peerIDs := req.Arguments
tokenStr := req.Options[tokencfg.TokenTypeName].(string)
token, bl := tokencfg.MpTokenAddr[tokenStr]
if !bl {
return errors.New("your input token is none. ")
}

for _, peerID := range peerIDs {
tx_hash, err := chain.SettleObject.SwapService.CashCheque(req.Context, peerID, token)
if err != nil {
return err
}
err = res.Emit(&CashChequeRet{
TxHash: tx_hash.String(),
})
if err != nil {
return err
}
}
return nil
},
Type: CashChequeRet{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *CashChequeRet) error {
_, err := fmt.Fprintf(w, "the hash of transaction: %s", out.TxHash)
return err
}),
},
}
1 change: 1 addition & 0 deletions core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func TestCommands(t *testing.T) {
"/cheque/token_balance",
"/cheque/all_token_balance",
"/cheque/cash",
"/cheque/batch-cash",
"/cheque/cashstatus",
"/cheque/chaininfo",
"/cheque/price",
Expand Down
Loading

0 comments on commit 83008eb

Please sign in to comment.