Skip to content

Commit

Permalink
Fork bswap (#88)
Browse files Browse the repository at this point in the history
* add fork bswap

* update go-nat and quic-go and qtls-go1-20
  • Loading branch information
AstaFrode authored Nov 13, 2023
1 parent 653a7a5 commit 43c9fcf
Show file tree
Hide file tree
Showing 20 changed files with 288 additions and 200 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"context"
"strings"

"github.com/AstaFrode/go-libp2p/core/connmgr"
"github.com/CESSProject/p2p-go/core"
"github.com/libp2p/go-libp2p/core/connmgr"
)

// Config describes a set of settings for a libp2p node
Expand Down
4 changes: 2 additions & 2 deletions core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"context"
"os"

"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/AstaFrode/go-libp2p/core/protocol"
"github.com/CESSProject/p2p-go/pb"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-msgio/pbio"
"github.com/pkg/errors"
)
Expand Down
4 changes: 2 additions & 2 deletions core/gentag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ package core
import (
"context"

"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/AstaFrode/go-libp2p/core/protocol"
"github.com/CESSProject/p2p-go/pb"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-msgio/pbio"
"github.com/pkg/errors"
)
Expand Down
245 changes: 124 additions & 121 deletions core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,39 @@ import (
"sync/atomic"
"time"

libp2pgrpc "github.com/AstaFrode/go-libp2p-grpc"
"github.com/CESSProject/p2p-go/out"
"github.com/CESSProject/p2p-go/pb"
libp2pgrpc "github.com/drgomesp/go-libp2p-grpc"
ggio "github.com/gogo/protobuf/io"
"github.com/gogo/protobuf/proto"

//bsnet "github.com/ipfs/boxo/bitswap/network"
//blocks "github.com/ipfs/go-block-format"

//ds_sync "github.com/ipfs/go-datastore/sync"

"github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/libp2p/go-libp2p/core/connmgr"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/discovery"
"github.com/libp2p/go-libp2p/core/event"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/core/routing"
drouting "github.com/libp2p/go-libp2p/p2p/discovery/routing"
dutil "github.com/libp2p/go-libp2p/p2p/discovery/util"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
bsnet "github.com/AstaFrode/boxo/bitswap/network"

bitswap "github.com/AstaFrode/boxo/bitswap"
blockstore "github.com/AstaFrode/boxo/blockstore"
blocks "github.com/ipfs/go-block-format"
ds_sync "github.com/ipfs/go-datastore/sync"

"github.com/AstaFrode/go-libp2p"
dht "github.com/AstaFrode/go-libp2p-kad-dht"
"github.com/AstaFrode/go-libp2p/core/connmgr"
"github.com/AstaFrode/go-libp2p/core/crypto"
"github.com/AstaFrode/go-libp2p/core/discovery"
"github.com/AstaFrode/go-libp2p/core/event"
"github.com/AstaFrode/go-libp2p/core/host"
"github.com/AstaFrode/go-libp2p/core/network"
"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/AstaFrode/go-libp2p/core/peerstore"
"github.com/AstaFrode/go-libp2p/core/protocol"
"github.com/AstaFrode/go-libp2p/core/routing"
drouting "github.com/AstaFrode/go-libp2p/p2p/discovery/routing"
dutil "github.com/AstaFrode/go-libp2p/p2p/discovery/util"
rcmgr "github.com/AstaFrode/go-libp2p/p2p/host/resource-manager"
"github.com/ipfs/go-cid"
"github.com/mr-tron/base58"
ma "github.com/multiformats/go-multiaddr"

//mh "github.com/multiformats/go-multihash"
mh "github.com/multiformats/go-multihash"
"github.com/pbnjay/memory"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -125,26 +128,26 @@ type P2P interface {
// Close p2p
Close() error

// //
// GetBlockstore() blockstore.Blockstore
//
GetBlockstore() blockstore.Blockstore

// //
// GetBitSwap() *bitswap.Bitswap
//
GetBitSwap() *bitswap.Bitswap

// //
// FidToCid(fid string) (string, error)
//
FidToCid(fid string) (string, error)

// //
// SaveAndNotifyDataBlock(buf []byte) (cid.Cid, error)
//
SaveAndNotifyDataBlock(buf []byte) (cid.Cid, error)

// //
// NotifyData(buf []byte) error
//
NotifyData(buf []byte) error

// // GetDataFromBlock get data from block
// GetDataFromBlock(ctx context.Context, wantCid string) ([]byte, error)
// GetDataFromBlock get data from block
GetDataFromBlock(ctx context.Context, wantCid string) ([]byte, error)

// //
// GetLocalDataFromBlock(wantCid string) ([]byte, error)
//
GetLocalDataFromBlock(wantCid string) ([]byte, error)

//
GetDiscoveredPeers() <-chan *routing.QueryEvent
Expand Down Expand Up @@ -306,21 +309,21 @@ type Node struct {
discoveredPeerCh <-chan *routing.QueryEvent
host host.Host
libp2pgrpcCli *libp2pgrpc.Client
//bstore blockstore.Blockstore
//bswap *bitswap.Bitswap
dir DataDirs
peerPublickey []byte
workspace string
privatekeyPath string
idleTee atomic.Value
serviceTee atomic.Value
serviceTagDataCh chan string
protocolVersion string
dhtProtocolVersion string
rendezvousVersion string
grpcProtocolVersion string
protocolPrefix string
bootstrap []string
bstore blockstore.Blockstore
bswap *bitswap.Bitswap
dir DataDirs
peerPublickey []byte
workspace string
privatekeyPath string
idleTee atomic.Value
serviceTee atomic.Value
serviceTagDataCh chan string
protocolVersion string
dhtProtocolVersion string
rendezvousVersion string
grpcProtocolVersion string
protocolPrefix string
bootstrap []string
*dht.IpfsDHT
*drouting.RoutingDiscovery
*protocols
Expand Down Expand Up @@ -463,83 +466,83 @@ func NewBasicNode(
return nil, err
}

// network := bsnet.NewFromIpfsHost(n.host, n.RoutingDiscovery)
// fsdatastore, err := NewDatastore(filepath.Join(n.workspace, FileBlockDir))
// if err != nil {
// return nil, err
// }
network := bsnet.NewFromIpfsHost(n.host, n.RoutingDiscovery)
fsdatastore, err := NewDatastore(filepath.Join(n.workspace, FileBlockDir))
if err != nil {
return nil, err
}

// n.bstore = blockstore.NewBlockstore(ds_sync.MutexWrap(fsdatastore))
// n.bswap = bitswap.New(
// n.ctxQueryFromCtxCancel,
// network,
// n.bstore,
// )
n.bstore = blockstore.NewBlockstore(ds_sync.MutexWrap(fsdatastore))
n.bswap = bitswap.New(
n.ctxQueryFromCtxCancel,
network,
n.bstore,
)

n.initProtocol(protocolPrefix)

return n, nil
}

// func (n *Node) GetBlockstore() blockstore.Blockstore {
// return n.bstore
// }

// func (n *Node) GetBitSwap() *bitswap.Bitswap {
// return n.bswap
// }

// // SaveAndNotifyDataBlock
// func (n *Node) SaveAndNotifyDataBlock(buf []byte) (cid.Cid, error) {
// blockData := blocks.NewBlock(buf)
// err := n.bstore.Put(n.ctxQueryFromCtxCancel, blockData)
// if err != nil {
// return blockData.Cid(), err
// }
// err = n.bswap.NotifyNewBlocks(n.ctxQueryFromCtxCancel, blockData)
// return blockData.Cid(), err
// }

// // NotifyData notify data
// func (n *Node) NotifyData(buf []byte) error {
// blockData := blocks.NewBlock(buf)
// return n.bswap.NotifyNewBlocks(n.ctxQueryFromCtxCancel, blockData)
// }

// // GetDataFromBlock get data from block
// func (n *Node) GetDataFromBlock(ctx context.Context, wantCid string) ([]byte, error) {
// wantcid, err := cid.Decode(wantCid)
// if err != nil {
// return nil, err
// }
// block, err := n.bswap.GetBlock(ctx, wantcid)
// if err != nil {
// return nil, err
// }
// return block.RawData(), err
// }

// // GetLocalDataFromBlock get local data from block
// func (n *Node) GetLocalDataFromBlock(wantCid string) ([]byte, error) {
// wantcid, err := cid.Decode(wantCid)
// if err != nil {
// return nil, err
// }
// block, err := n.bstore.Get(n.ctxQueryFromCtxCancel, wantcid)
// if err != nil {
// return nil, err
// }
// return block.RawData(), err
// }

// // FidToCid
// func (n *Node) FidToCid(fid string) (string, error) {
// mhash, err := mh.FromHexString("1220" + fid)
// if err != nil {
// return "", err
// }
// return cid.NewCidV0(mhash).String(), nil
// }
func (n *Node) GetBlockstore() blockstore.Blockstore {
return n.bstore
}

func (n *Node) GetBitSwap() *bitswap.Bitswap {
return n.bswap
}

// SaveAndNotifyDataBlock
func (n *Node) SaveAndNotifyDataBlock(buf []byte) (cid.Cid, error) {
blockData := blocks.NewBlock(buf)
err := n.bstore.Put(n.ctxQueryFromCtxCancel, blockData)
if err != nil {
return blockData.Cid(), err
}
err = n.bswap.NotifyNewBlocks(n.ctxQueryFromCtxCancel, blockData)
return blockData.Cid(), err
}

// NotifyData notify data
func (n *Node) NotifyData(buf []byte) error {
blockData := blocks.NewBlock(buf)
return n.bswap.NotifyNewBlocks(n.ctxQueryFromCtxCancel, blockData)
}

// GetDataFromBlock get data from block
func (n *Node) GetDataFromBlock(ctx context.Context, wantCid string) ([]byte, error) {
wantcid, err := cid.Decode(wantCid)
if err != nil {
return nil, err
}
block, err := n.bswap.GetBlock(ctx, wantcid)
if err != nil {
return nil, err
}
return block.RawData(), err
}

// GetLocalDataFromBlock get local data from block
func (n *Node) GetLocalDataFromBlock(wantCid string) ([]byte, error) {
wantcid, err := cid.Decode(wantCid)
if err != nil {
return nil, err
}
block, err := n.bstore.Get(n.ctxQueryFromCtxCancel, wantcid)
if err != nil {
return nil, err
}
return block.RawData(), err
}

// FidToCid
func (n *Node) FidToCid(fid string) (string, error) {
mhash, err := mh.FromHexString("1220" + fid)
if err != nil {
return "", err
}
return cid.NewCidV0(mhash).String(), nil
}

// DHTFindPeer searches for a peer with given ID.
func (n *Node) DHTFindPeer(peerid string) (peer.AddrInfo, error) {
Expand Down
2 changes: 1 addition & 1 deletion core/poisService_p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"context"
"time"

"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/CESSProject/p2p-go/pb"
"github.com/libp2p/go-libp2p/core/peer"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down
2 changes: 1 addition & 1 deletion core/pois_p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/CESSProject/p2p-go/pb"
"github.com/libp2p/go-libp2p/core/peer"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down
4 changes: 2 additions & 2 deletions core/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ package core
import (
"context"

"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/AstaFrode/go-libp2p/core/protocol"
"github.com/CESSProject/p2p-go/pb"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-msgio/pbio"
"github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion core/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
package core

import (
"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/CESSProject/p2p-go/pb"
"github.com/libp2p/go-libp2p/core/peer"
)

type Protocol interface {
Expand Down
6 changes: 3 additions & 3 deletions core/pushTag.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"path/filepath"
"time"

"github.com/AstaFrode/go-libp2p/core/network"
"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/AstaFrode/go-libp2p/core/protocol"
"github.com/CESSProject/p2p-go/pb"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-msgio/pbio"
"github.com/pkg/errors"
)
Expand Down
6 changes: 3 additions & 3 deletions core/readdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"github.com/CESSProject/p2p-go/pb"
"github.com/pkg/errors"

"github.com/AstaFrode/go-libp2p/core/network"
"github.com/AstaFrode/go-libp2p/core/peer"
"github.com/AstaFrode/go-libp2p/core/protocol"
"github.com/gogo/protobuf/proto"
"github.com/google/uuid"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
)

// pattern: /protocol-name/request-or-response-message/version
Expand Down
Loading

0 comments on commit 43c9fcf

Please sign in to comment.