一起来读源码203-Ipfs cmd

摘要

ipfs核心部件

详情

bootstrap/bootsrap.go

commands/cmdenv/cidbase.go

command/cmdenv/env.go

command/cmdenv/file.go

command/dag/dag.go

commands/e/error.go

commands/name/ipns.go

commands/name/ipnsps.go

commands/name/name.go

commands/name/publish.go

commands/object/diff.go

commands/object/object.go

commands/object/patch.go

commands/unixfs/ls.go

commands/unixfs/unixfs.go

commands/active.go

commands/add.go

commands/bitswap.go

commands/block.go

定义全局变量

var ErrNotEnoughBootstrapPeers = errors.New("not enough bootstrap peers to bootstrap") //bootstrap节点不够
var ErrDataEncoding = errors.New("unknown data field encoding") //无法编码
//默认节点配置
var DefaultBootstrapConfig = BootstrapConfig{
	MinPeerThreshold:  4,
	Period:            30 * time.Second,
	ConnectionTimeout: (30 * time.Second) / 3, // Perod / 3
}

//命令 dag
var DagCmd = &cmds.Command{}
//命令 DagPut
var DagPutCmd = &cmds.Command{}
//命令 DagGet
var DagGetCmd = &cmds.Command{}
//命令 DagResolve
var DagResolveCmd = &cmds.Command{}
//命令 DagImport
var DagImportCmd = &cmds.Command{}
//命令 Dag导出
var DagExportCmd = &cmds.Command{}
//命令 Ipns
var IpnsCmd = &cmds.Command{}
//命令 Ipns发布订阅
var IpnsPubsubCmd = &cmds.Command{}
//命令 Name
var NameCmd = &cmds.Command{}
//命令 publish
var PublishCmd = &cmds.Command{}
//命令 Object
var ObjectCmd = &cmds.Command{}
//命令 ObjectData
var ObjectDataCmd = &cmds.Command{}
//命令 ObjectLinks
var ObjectLinksCmd = &cmds.Command{}
//命令 ObjectGet
var ObjectGetCmd = &cmds.Command{}
//命令 ObjectStat
var ObjectStatCmd = &cmds.Command{}
//命令 ObjectPut
var ObjectPutCmd = &cmds.Command{}
//命令 ObjectNew
var ObjectNewCmd = &cmds.Command{}
//命令 ObjectPatch
var ObjectPatchCmd = &cmds.Command{}
//命令 ls
var LsCmd = &cmds.Command{}
//命令 UnixFS
var UnixFSCmd = &cmds.Command{}
//命令 列出正在跑或最近跑过的命令
var ActiveReqsCmd = &cmds.Command{}
//命令 Add
var AddCmd = &cmds.Command{}
//命令 bitswap
var BitswapCmd = &cmds.Command{}
//命令 
var BlockCmd = &cmds.Command{}

//输出管道尺寸
const adderOutChanSize = 8

定义全局函数

//设置节点配置的节点集合
func BootstrapConfigWithPeers(pis []peer.AddrInfo) BootstrapConfig
//定期检查连接,如果数量过少,初始化连接集合
func Bootstrap(id peer.ID, host host.Host, rt routing.Routing, cfg BootstrapConfig) (io.Closer, error)
//获得cid编码器
func GetCidEncoder(req *cmds.Request) (cidenc.Encoder, error) 
//获得一个低级的cid编码器
func GetLowLevelCidEncoder(req *cmds.Request) (cidenc.Encoder, error)
//是否定义了cid-base
func CidBaseDefined(req *cmds.Request) bool
//根据路径格式返回编码器
func CidEncoderFromPath(p string) (cidenc.Encoder, error) 
//返回环境中的节点
func GetNode(env interface{}) (*core.IpfsNode, error)
//从env中提取api
func GetApi(env cmds.Environment, req *cmds.Request) (coreiface.CoreAPI, error)
//根据上下文返回配置
func GetConfig(env cmds.Environment) (*config.Config, error)
//根据roo上下文返回配置
func GetConfigRoot(env cmds.Environment) (string, error)
//根据目录迭代器返回文件
func GetFileArg(it files.DirIterator) (files.File, error)
//类型错误
func TypeErr(expected, actual interface{}) error

定义类

//节点配置
type BootstrapConfig struct {
    MinPeerThreshold int                    //最小节点阀值
    Period time.Duration                    //周期
    ConnectionTimeout time.Duration         //连接超时
    BootstrapPeers func() []peer.AddrInfo   //返回节点集合
}

//命令dag put 返回结果
type OutputObject struct {
	Cid cid.Cid
}

//命令dag resolve 返回结果
type ResolveOutput struct {
	Cid     cid.Cid
	RemPath string
}

//命令dag import 返回结果
type CarImportOutput struct {
	Root RootMeta
}

//
type RootMeta struct {
	Cid         cid.Cid
	PinErrorMsg string
}

//回调错误
type HandlerError struct {
	Err   error
	Stack []byte

    func (err HandlerError) Error() string  //错误
    func New(err error) HandlerError        //根据错误新建回调
}

//处理后的路径
type ResolvedPath struct {
	Path path.Path
}
//ipns实体
type IpnsEntry struct {
    Name  string //名字
    Value string //值
}
//节点
type Node struct {
    Links []Link //连接集合
    Data string  //数据
}
//链接
type Link struct {
    Name, Hash string //链接名字,hash
    Size       uint64 //尺寸
}
//对象
type Object struct {
    Hash  string //hash
    Links []Link //链接对象
}
//
type LsLink struct {
	Name, Hash string
	Size       uint64
	Type       string
}
//
type LsObject struct {
	Hash  string
	Size  uint64
	Type  string
	Links []LsLink
}
//
type LsOutput struct {
	Arguments map[string]string
	Objects   map[string]*LsObject
}
//添加事件
type AddEvent struct {
	Name  string
	Hash  string `json:",omitempty"`
	Bytes int64  `json:",omitempty"`
	Size  string `json:",omitempty"`
}
//块状态
type BlockStat struct {
    Key string  //块key
    Size int    //块大小
    String() string //打印块状态
}

猜你喜欢

转载自blog.csdn.net/qq_27304213/article/details/107695968
cmd
今日推荐