github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/swarm/pss/client/doc.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:44</date>
    10  //</624450116475949056>
    11  
    12  
    13  //实现PSS功能的简单抽象
    14  //
    15  //PSS客户端库旨在简化在PSS上使用p2p.protocols包的过程。
    16  //
    17  //IO使用普通的p2p.msgreadwriter接口执行,该接口使用websockets作为传输层,使用swarm/pss包中pssapi类中的方法,通过rpc透明地与pss节点通信。
    18  //
    19  //
    20  //最小ISH使用示例(需要具有WebSocket RPC的正在运行的PSS节点):
    21  //
    22  //
    23  //进口(
    24  //“语境”
    25  //“FMT”
    26  //“操作系统”
    27  //pss“github.com/ethereum/go-ethereum/swarm/pss/client”
    28  //“github.com/ethereum/go-ethereum/p2p/协议”
    29  //“github.com/ethereum/go-ethereum/p2p”
    30  //“github.com/ethereum/go-ethereum/swarm/pot”
    31  //“github.com/ethereum/go-ethereum/swarm/log”
    32  //)
    33  //
    34  //FOOMSG结构类型
    35  //条形图
    36  //}
    37  //
    38  //
    39  //func foohandler(msg interface)错误
    40  //foomsg,确定:=msg.(*foomsg)
    41  //如果OK {
    42  //log.debug(“yay,刚收到一条消息”,“msg”,foomsg)
    43  //}
    44  //返回errors.new(fmt.sprintf(“未知消息”))
    45  //}
    46  //
    47  //规格:=&protocols.spec
    48  //姓名:“福”,
    49  //版本:1,
    50  //最大尺寸:1024,
    51  //消息:[]接口
    52  //FoMsg{}
    53  //}
    54  //}
    55  //
    56  //协议:=&p2p.协议
    57  //名称:规格名称,
    58  //版本:规范版本,
    59  //长度:uint64(len(spec.messages)),
    60  //运行:func(p*p2p.peer,rw p2p.msgreadwriter)错误
    61  //p p:=protocols.newpeer(p,rw,spec)
    62  //返回PP.RUN(Foohandler)
    63  //}
    64  //}
    65  //
    66  //func实现()
    67  //cfg:=pss.newclientconfig()。
    68  //psc:=pss.newclient(context.background(),nil,cfg)
    69  //错误:=psc.start())
    70  //如果犯错!= nIL{
    71  //log.crit(“无法启动PSS客户端”)
    72  //退出(1)
    73  //}
    74  //
    75  //log.debug(“连接到PSS节点”,“bzz addr”,psc.baseaddr)
    76  //
    77  //err=psc.runprotocol(协议)
    78  //如果犯错!= nIL{
    79  //log.crit(“无法在PSS WebSocket上启动协议”)
    80  //退出(1)
    81  //}
    82  //
    83  //地址:=pot.randomaddress()//当然应该是一个真实地址
    84  //psc.addpsspeer(地址,规格)
    85  //
    86  ////使用协议
    87  //
    88  //停止()
    89  //}
    90  //
    91  //bug(测试):由于蜂群蜂巢中的死锁问题,测试超时
    92  package client
    93