github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/swarm/api/config.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:43</date> 10 //</624450111459561472> 11 12 13 package api 14 15 import ( 16 "crypto/ecdsa" 17 "fmt" 18 "os" 19 "path/filepath" 20 "time" 21 22 "github.com/ethereum/go-ethereum/common" 23 "github.com/ethereum/go-ethereum/contracts/ens" 24 "github.com/ethereum/go-ethereum/crypto" 25 "github.com/ethereum/go-ethereum/node" 26 "github.com/ethereum/go-ethereum/p2p/enode" 27 "github.com/ethereum/go-ethereum/swarm/log" 28 "github.com/ethereum/go-ethereum/swarm/network" 29 "github.com/ethereum/go-ethereum/swarm/pss" 30 "github.com/ethereum/go-ethereum/swarm/services/swap" 31 "github.com/ethereum/go-ethereum/swarm/storage" 32 ) 33 34 const ( 35 DefaultHTTPListenAddr = "127.0.0.1" 36 DefaultHTTPPort = "8500" 37 ) 38 39 //单独的BZZ目录 40 //允许多个bzz节点并行运行 41 type Config struct { 42 //序列化/持久化字段 43 *storage.FileStoreParams 44 *storage.LocalStoreParams 45 *network.HiveParams 46 Swap *swap.LocalProfile 47 Pss *pss.PssParams 48 /*网络.syncparams 49 合同通用地址 50 ENSROOT公用地址 51 ensapis[]字符串 52 路径字符串 53 listenaddr字符串 54 端口字符串 55 公钥字符串 56 bzzkey字符串 57 nodeid字符串 58 网络ID uint64 59 可旋转吊杆 60 同步启用布尔值 61 同步kipcheck bool 62 交付kipcheck bool 63 maxstreampeerservers int 64 轻节点启用bool 65 同步更新延迟时间。持续时间 66 SWAPPI字符串 67 CORS弦 68 bzzaccount字符串 69 私钥*ecdsa.privatekey 70 } 71 72 //创建一个默认配置,所有参数都设置为默认值 73 func newconfig()(c*config) 74 75 C=和CONFIG { 76 localstoreparams:storage.newdefaultlocalstoreparams(), 77 filestoreparams:storage.newfilestoreparams(), 78 hiveParams:network.newhiveParams(), 79 //同步参数:network.newDefaultSyncParams(), 80 swap:swap.newdefaultswapparams(), 81 pss:pss.newpssparams(), 82 listenaddr:默认httplistenaddr, 83 端口:默认httpport, 84 路径:node.defaultdatadir(), 85 ENSAPI:无, 86 ensroot:ens.testnetaddress,网址: 87 networkid:network.defaultnetworkid, 88 SWAPENABLED:错误, 89 已启用同步:真, 90 SyncingSkipCheck:错误, 91 MaxstreamPeerServers:10000台, 92 DeliverySkipCheck:是, 93 同步更新延迟:15*次。秒, 94 斯瓦帕皮:“, 95 } 96 97 返回 98 } 99 100 //完成后需要初始化一些配置参数 101 //配置构建阶段已完成(例如,由于覆盖标志) 102 func(c*config)init(prvkey*ecdsa.privatekey) 103 104 地址:=crypto.pubkeytoAddress(prvkey.publickey) 105 c.path=filepath.join(c.path,“bzz-”+common.bytes2hex(address.bytes())) 106 错误:=os.mkdirall(c.path,os.modeperm) 107 如果犯错!= nIL{ 108 log.error(fmt.sprintf(“创建根Swarm数据目录时出错:%v”,err))。 109 返回 110 } 111 112 pubkey:=crypto.fromecdsapub(&prvkey.publickey) 113 pubkeyhex:=common.tohex(pubkey) 114 keyHex:=crypto.keccak256hash(pubkey.hex()) 115 116 c.publickey=pubKeyHex 117 c.bzzkey=六角键 118 c.nodeid=enode.pubKeyToIDv4(&prvkey.publickey).string()) 119 120 如果C.SWAPENABLED 121 c.swap.init(c.contract,prvkey) 122 } 123 124 c.privatekey=prvkey 125 c.localstoreparams.init(c.path)初始化 126 c.localstoreparams.basekey=common.fromhex(keyhex) 127 128 c.pss=c.pss.withprivatekey(c.privatekey) 129 } 130 131 func(c*config)shiftprivatekey()(privkey*ecdsa.privatekey) 132 如果是C.privatekey!= nIL{ 133 privkey=c.privatekey 134 c.privatekey=无 135 } 136 返回私钥 137 } 138