mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00
skeleton.
This commit is contained in:
10
README.md
Normal file
10
README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# ipfs implementation in go.
|
||||||
|
|
||||||
|
See: https://github.com/jbenet/ipfs
|
||||||
|
|
||||||
|
Please put all issues regarding IPFS _design_ in the
|
||||||
|
[ipfs repo issues](https://github.com/jbenet/ipfs/issues).
|
||||||
|
|
||||||
|
Please put all issues regarding go IPFS _implementation_ in [this repo](https://github.com/jbenet/go-ipfs/issues).
|
||||||
|
|
||||||
|
The [node implementation](https://github.com/jbenet/node-ipfs) is much farther along. This one is just a skeleton.
|
17
bitswap/bitswap.go
Normal file
17
bitswap/bitswap.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package bitswap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jbenet/go-ipfs/peer"
|
||||||
|
)
|
||||||
|
|
||||||
|
// aliases
|
||||||
|
|
||||||
|
type Ledger struct {
|
||||||
|
// todo
|
||||||
|
}
|
||||||
|
|
||||||
|
type BitSwap struct {
|
||||||
|
Ledgers map[peer.PeerId]*Ledger
|
||||||
|
HaveList map[multihash.Multihash]*block.Block
|
||||||
|
WantList []*multihash.Multihash
|
||||||
|
}
|
10
block/block.go
Normal file
10
block/block.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package block
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jbenet/go-multihash"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Block struct {
|
||||||
|
Multihash []byte
|
||||||
|
Data []byte
|
||||||
|
}
|
14
blocks/blocks.go
Normal file
14
blocks/blocks.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package blocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jbenet/go-ipfs/bitswap"
|
||||||
|
"github.com/jbenet/go-ipfs/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Blocks is the ipfs blocks service. It is the way
|
||||||
|
// to retrieve blocks by the higher level ipfs modules
|
||||||
|
|
||||||
|
type BlockService struct {
|
||||||
|
Local *storage.Storage
|
||||||
|
Remote *bitswap.BitSwap
|
||||||
|
}
|
33
core/core.go
Normal file
33
core/core.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
// IPFS Core module. It represents an IPFS instance.
|
||||||
|
|
||||||
|
type IPFSNode struct {
|
||||||
|
|
||||||
|
// the local node's identity (a Peer instance)
|
||||||
|
Identity *peer.Peer
|
||||||
|
|
||||||
|
// the book of other nodes (a hashtable of Peer instances)
|
||||||
|
PeerBook *peerbook.PeerBook
|
||||||
|
|
||||||
|
// the local database (uses datastore)
|
||||||
|
Storage *storage.Storage
|
||||||
|
|
||||||
|
// the network message stream
|
||||||
|
Network *netmux.Netux
|
||||||
|
|
||||||
|
// the routing system. recommend ipfs-dht
|
||||||
|
Routing *routing.Routing
|
||||||
|
|
||||||
|
// the block exchange + strategy (bitswap)
|
||||||
|
BitSwap *bitswap.BitSwap
|
||||||
|
|
||||||
|
// the block service, get/add blocks.
|
||||||
|
Blocks *blocks.BlockService
|
||||||
|
|
||||||
|
// the path resolution system
|
||||||
|
Resolver *resolver.PathResolver
|
||||||
|
|
||||||
|
// the name system, resolves paths to hashes
|
||||||
|
Namesys *namesys.Namesys
|
||||||
|
}
|
7
dht/dht.go
Normal file
7
dht/dht.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package dht
|
||||||
|
|
||||||
|
// The IPFS DHT is an implementation of Kademlia with
|
||||||
|
// Coral and S/Kademlia modifications. It is used to
|
||||||
|
// implement the base IPFS Routing module.
|
||||||
|
|
||||||
|
TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
|
0
msgproto/msgproto.go
Normal file
0
msgproto/msgproto.go
Normal file
96
netmux/interface.go
Normal file
96
netmux/interface.go
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
package netmux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// An interface is the module connecting netmux
|
||||||
|
// to various networks (tcp, udp, webrtc, etc).
|
||||||
|
// It keeps the relevant connections open.
|
||||||
|
type Interface struct {
|
||||||
|
|
||||||
|
// Interface network (e.g. udp4, tcp6)
|
||||||
|
Network string
|
||||||
|
|
||||||
|
// Own network address
|
||||||
|
Address string
|
||||||
|
ResolvedAddress string
|
||||||
|
|
||||||
|
// Connection
|
||||||
|
conn *net.Conn
|
||||||
|
|
||||||
|
// next packets + close control channels
|
||||||
|
Input chan *Packet
|
||||||
|
Output chan *Packet
|
||||||
|
Closed chan bool
|
||||||
|
Errors chan error
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUDPInterface(net, addr string) (*Interface, error) {
|
||||||
|
raddr, err := net.ResolveUDPAddr(net, addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := net.ListenUDP(net, addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
i := &Interface{
|
||||||
|
Network: net,
|
||||||
|
Address: addr,
|
||||||
|
ResolvedAddress: raddr,
|
||||||
|
conn: conn,
|
||||||
|
}
|
||||||
|
|
||||||
|
go i.processInput()
|
||||||
|
go i.processOutput()
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Interface) processOutput() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-i.Closed:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case buffer := <-i.Output:
|
||||||
|
i.conn.Write([]byte(buffer))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Interface) processUDPInput() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <- i.Closed:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Interface) Read(buffer []byte) bool {
|
||||||
|
n, err := i.Conn.Read(buffer)
|
||||||
|
if err != nil {
|
||||||
|
i.Errors <- err
|
||||||
|
i.Close()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Interface) Close() {
|
||||||
|
// closing net connection
|
||||||
|
err := i.conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
i.Errors <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
// closing channels
|
||||||
|
close(i.Input)
|
||||||
|
close(i.Output)
|
||||||
|
close(i.Closed)
|
||||||
|
close(i.Errors)
|
||||||
|
}
|
51
netmux/netmux.go
Normal file
51
netmux/netmux.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package netmux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The netmux module provides a "network multiplexer".
|
||||||
|
// The core idea is to have the client be able to connect to
|
||||||
|
// many different networks (potentially over different transports)
|
||||||
|
// and multiplex everything over one interface.
|
||||||
|
|
||||||
|
type Netmux struct {
|
||||||
|
// the list of NetMux interfaces
|
||||||
|
Interfaces []*Interface
|
||||||
|
|
||||||
|
// The channels to send/recv from
|
||||||
|
Incoming <-chan *Packet
|
||||||
|
Outgoing chan<- *Packet
|
||||||
|
|
||||||
|
// internally managed other side of channels
|
||||||
|
incomingSrc chan<- *Packet
|
||||||
|
outgoingSrc <-chan *Packet
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Warning: will probably change to adopt multiaddr format
|
||||||
|
type Packet {
|
||||||
|
// the network addresses to send to
|
||||||
|
// e.g. tcp4://127.0.0.1:12345
|
||||||
|
NetAddrTo string
|
||||||
|
|
||||||
|
// the network addresses to recv from
|
||||||
|
// e.g. tcp4://127.0.0.1:12345
|
||||||
|
// may be left blank to select one automatically.
|
||||||
|
NetAddrFrom string
|
||||||
|
|
||||||
|
// the data to send.
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNetmux() *Netmux {
|
||||||
|
n := &Netmux{}
|
||||||
|
|
||||||
|
// setup channels
|
||||||
|
och := make(chan *Packet)
|
||||||
|
ich := make(chan *Packet)
|
||||||
|
n.Incoming, n.incomingSrc := ich, ich
|
||||||
|
n.Outgoing, n.outgoingSrc := och, och
|
||||||
|
|
||||||
|
return n
|
||||||
|
}
|
0
object/object.go
Normal file
0
object/object.go
Normal file
0
path/path.go
Normal file
0
path/path.go
Normal file
0
peer/peer.go
Normal file
0
peer/peer.go
Normal file
4
routing/routing.go
Normal file
4
routing/routing.go
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package routing
|
||||||
|
|
||||||
|
|
||||||
|
TODO SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-routing/index.js
|
0
storage/storage.go
Normal file
0
storage/storage.go
Normal file
Reference in New Issue
Block a user