Docker 本身DNS是不穩定的

再分享早上碰到docker穩定度問題,docker內到外網是靠本機的iptables做Nat出去,早上就發現運行很久的docker container,突然不送資料到ELK,一查發現DNS掛了,這之前也碰到幾次了,基本上不是中心DNS掛了,而且Docker本身架構的DNS掛了,基本上只要重啟docker service後就正常,無需對主機重啟,而重啟docker service是一件很嚴重的事情,因為上面所有的服務都會一併被下線,之後還要在把運行的服務全部重新上線… 也許我的理解是錯誤,但只能以目前的情況來判斷,也許是iptables nat轉換的問題,但本機沒有重開機,理論上就沒有這個問題才是。

2019-11-07 · 1 min · 6 words · Me

[轉]What's New in Ethereum Serenity (2.0)

http://kimiwublog.blogspot.com/2018/12/whats-new-in-ethereum-serenity-20.html 需注意,時間是2018/12/06 內容肯不會是最正確的

2019-11-06 · 1 min · 3 words · Me

[DIY] HyperLedger

1. Use docker-machine crate docker vm. And install docker-compose. 2. https://github.com/hyperledger/fabric-samples # Fetch bootstrap.sh from fabric repository using curl -sS https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh -o ./scripts/bootstrap.sh # Change file mode to executable chmod +x ./scripts/bootstrap.sh # Download binaries and docker images #./scripts/bootstrap.sh [version] [ca version] [thirdparty_version] ./scripts/bootstrap.sh Here use all default value. 3. https://hyperledger-fabric.readthedocs.io/en/latest/build_network.html # Start Run cd fabric-samples/first-network ./byfn.sh generate ./byfn.sh up 4. Hope you see ===================== Query successful on peer1.org2 on channel ‘mychannel’ ===================== ...

2019-11-05 · 1 min · 204 words · Me

[轉]SSLH 是一款采用 C 语言编写的开源端口复用软件,目前支持 HTTP、SSL、SSH、OpenVPN、Tinc、XMPP 等多种协议识别

https://mp.weixin.qq.com/s/sHitMzs8KXXO6joX8QqO_A?fbclid=IwAR1UGD7gemvKRY-IkOCEHGDru6YLDkI2vXojKpLTc-AZ4gN2Zz849YwJKZ8 SSLH 是一款采用 C 语言编写的开源端口复用软件,目前支持 HTTP、SSL、SSH、OpenVPN、Tinc、XMPP 等多种协议识别。它主要运行于 *nix 环境,源代码托管在 GitHub 上。 项目地址:https://github.com/yrutschle/sslh 更简单地说,SSLH 允许我们在 Linux 系统上的同一端口上运行多个程序/服务。因此,您可以用同一端口来同时使用两种服务。如果你遇到大多数端口被防火墙阻止的情况,SSLH 就可以帮你派上大用场。下面我们就来看一个 SSL 和 SSH 同时复用同一端口的实例。

2019-11-01 · 1 min · 21 words · Me

[轉][Flutter]还在大量使用TextEditingController?试试这种解决方案

当用户输入大量信息时,通常会采用TextField列表来解决,这时如果需要对每个TextField进行控制或监听就需要大量的TextEditingController。 这里提供另一种思路,解决大量使用TextEditingController和信息整理困难的问题。 定义一个Map: Map _userInfo; 这个Map作用于所有需要收集用户信息的地方。 使用TextField时这样操作: ////邮箱 TextField( controller: TextEditingController(text: _userInfo['account']), onChanged: (value) { _userInfo['account'] = value; }, ), ////昵称 TextField( controller: TextEditingController(text: _userInfo['nickname']), onChanged: (value) { _userInfo['nickname'] = value; }, ), ////密码 TextField( controller: TextEditingController(text: _userInfo['password']), onChanged: (value) { _userInfo['password'] = value; }, ), 这里全程未单独定义TextEditingController,只使用TextField默认的方法进行控制,且可以获得以下好处: 1.节省大量代码,简化业务逻辑。 2.用户输入完成时即得到一个包含所有信息的Map。 3.输入的内容不会丢失,只要这个Map不被销毁,下次进入(或返回)这个页面时所有内容都在,不用要求用户再次输入,提升用户体验。 第一次发文章,如有问题,欢迎指正。 作者:xSILENCEx 链接:https://juejin.im/post/5d649bfce51d453b1d648314 来源:掘金 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

2019-10-31 · 1 min · 55 words · Me

dart null list

減少null判斷情況 https://stackoverflow.com/questions/51036758/flutter-the-method-map-was-called-on-null https://juejin.im/post/5c6d38b1f265da2dcc7feb69 https://cloud.tencent.com/developer/article/1370380 ?? => if null https://blog.csdn.net/ffa_ijj/article/details/85051156 return qres?.map((value) { LinkedHashMap result = json.decode(value["jsonitem"]); return result; })?.first ?? new LinkedHashMap(); 這個判斷方式有個問題,當查詢回來為[],不是null情況下,在.first會出錯,因為 “No element"會出錯,但.toList()會正確,故改回 if (qres == null || qres.isEmpty) return new Member(); // 待確定是否出錯 var resmap = qres.first; return new Member.fromJson(json.decode(resmap["jsonitem"]));

2019-10-24 · 1 min · 43 words · Me

git 不同專案使用不同帳號

git global 已設定,但其他專案需要設定其他的帳號 到專案目錄下的.git內,修改config檔案,補上 [user] name = ooxx email = ooxx@gmail.com 即可蓋過global

2019-10-23 · 1 min · 12 words · Me

dart json serialisation dson

https://github.com/drails-dart/dart-serialise https://github.com/parnham/dart-serialise https://github.com/dart-league/dson

2019-10-23 · 1 min · 3 words · Me

Android Studio AVD Path

windows system path ANDROID_AVD_HOME

2019-10-19 · 1 min · 4 words · Me

json to dart flutter

https://javiercbk.github.io/json_to_dart/ https://ashamp.github.io/jsonToDartModel/

2019-10-18 · 1 min · 2 words · Me

frp reverse proxy 反向代理

https://github.com/fatedier/frp

2019-10-15 · 1 min · word · Me

[轉]Remix now force to use https, how can i continue to use http://remix.ethereum.org?

http://remix.ethereum.org Not https://remix.ethereum.org

2019-10-14 · 1 min · 3 words · Me

[轉]kubernetes高可用安装工具,一条命令,离线安装,包含所有依赖,内核负载不依赖haproxy keepalived,纯golang开发,99年证书,

https://github.com/fanux/sealos

2019-10-14 · 1 min · word · Me

[轉]datatable datatables nodejs

https://newcodingera.com/datatables-server-side-processing-using-nodejs-mysql/ https://1drv.ms/u/s!At2KEcnT9DVaiw88MAEXeML0bRf3 Important! SqlInjection ====================== datatables mongodb https://github.com/deepikagunda/datatables

2019-10-08 · 1 min · 8 words · Me

[轉]secp256k1簽章的message,長度都必須是256 bits,也就是32 bytes

https://medium.com/@antonassocareer/web3-secp256k1-%E7%B0%BD%E7%AB%A0%E8%88%87solidity%E9%A9%97%E7%AB%A0-26ded518cfdc 那麼如果我們想要單純用私鑰簽章一段資料,不要有Ethereum定義的那些prefix的話,就必須要直接調用 secp256k1 這一包library了。不過在用之前要知道,所有要丟給secp256k1簽章的message,長度都必須是256 bits,也就是32 bytes。剛剛我們說web3的簽名函式丟什麼都可以,是因為它會幫我加上prefix之後再做sha3 Hash (keccak),最後一定會變成一個32 bytes的東西。如果我們自己純靠私要簽章訊息的話,也勢必要先通過這個函式來整理input長度 sha3 Hash (keccak)

2019-10-07 · 1 min · 12 words · Me

bip39 mnemonic bip32 seed ed25519 elliptic

const bip39 = require('bip39') const bip32 = require('bip32'); const EC = require('elliptic').ec; json =`test json file` mnemonic = "簡 熙 夢 幾 聲 可 高 汪 煙 版 統 仇" path = "m/2018'/5'/1'/0/1" const sJWSinit = async () => { console.log('-----sJWS Initial Start----- \n'); dkey = await DeriveKey(mnemonic, path) console.log("\nGet dkey: %o \n", dkey) console.log('\n-----elliptic ed25519 Start----- \n'); var EdDSA = require('elliptic').eddsa var ec = new EdDSA('ed25519'); var eckeypair = ec.keyFromSecret(dkey.privateKey) var privateKeyHex = new Buffer.from(eckeypair.getSecret()).toString('hex') var publickeyHex = new Buffer.from(eckeypair.getPublic()).toString('hex') console.log("private key hex: %o", privateKeyHex) console.log("public key hex: %o\n", publickeyHex) var signature = eckeypair.sign(json).toHex(); console.log("signature: %o\n", signature) var ec2 = new EdDSA('ed25519'); var ec2keypair2 = ec2.keyFromPublic(publickeyHex, 'hex'); console.log("EdDSA json verify: %o", ec2keypair2.verify(json, signature)); } (async () => { console.log("--- aysnc sJWS init---") await sJWSinit(); })(); async function DeriveKey(mnemonic, derivePath) { if (bip39.validateMnemonic(mnemonic)) { console.log("mnemonic is fake!") } return bip39.mnemonicToSeed(mnemonic).then((vseed)=>{ var root = bip32.fromSeed(vseed) var PathNode = root.derivePath(derivePath) console.log("# PATH 是 m/2018'/5'/1'/0/1/0 因為底下為derive(0),所以 path + '/0' \n") console.log("privateKey (Hex): %o", PathNode.derive(0).privateKey.toString('hex')) console.log("publicKey (Hex): %o", PathNode.derive(0).publicKey.toString('hex')) // 024ac10a81e3a0f86cb4dad68c6a26031d805a057f36048f80a5b91b1c2cb0588c 符合 return { prv_buf: PathNode.derive(0).privateKey, pub_buf: PathNode.derive(0).publicKey, wif: PathNode.derive(0).toWIF(), publicKey: PathNode.derive(0).publicKey.toString('hex'), privateKey: PathNode.derive(0).privateKey.toString('hex'), path: derivePath } }).catch((e) => { console.error('handle error here: ', e.message) }) }

2019-10-07 · 1 min · 193 words · Me

bitcoinjs-lib HDNode.fromSeedBuffer error bip39 bip32 Address bitcoin ethereum

bitcoinSecp256r1.HDNode.fromSeedBuffer 無法使用,目前正確應該是用 bitcoinSecp256r1.bip32.fromSeed jsrsasign 有異常 const bip39 = require('bip39') const bip32 = require('bip32'); const bitcoinSecp256r1 = require('bitcoinjs-lib') const ethUtil = require('ethereumjs-util') const EC = require('elliptic').ec; // bitcoinSecp256r1.HDNode.fromSeedBuffer 無法使用,目前正確應該是用 bitcoinSecp256r1.bip32.fromSeed mnemonic = "簡 熙 夢 幾 聲 可 高 汪 煙 版 統 仇" path = "m/2018'/5'/1'/0/1" type = "secp256r1" // 驗證網頁 https://iancoleman.io/bip39/#chinese_traditional if (bip39.validateMnemonic(mnemonic)) { console.log("mnemonic is fake!") } const seed = bip39.mnemonicToSeed(mnemonic).then((vseed)=>{ var root = bip32.fromSeed(vseed) var PathNode = root.derivePath(path) console.log("---------------------------------------------") console.log("# PATH 是 m/2018'/5'/1'/0/1/ \n") console.log("Bitcoin Address: %o 符合 \n", getAddress(PathNode)) // 1GcgQJN7XgqkZkQcD4dzaZ7bjCFvQ6wxF2 符合 m/2018'/5'/1'/0/1 console.log("root toWIF: %o", root.toWIF()) console.log("PathNode toWIF: %o 符合", PathNode.toWIF()) // Kzq7FAYiWjDAcwU44FvcyCsCpJyLCD19n13FyQgLY6oBNajYcAYz 符合 m/2018'/5'/1'/0/1 console.log("--------------------------------------------- \n") // 底下為derive(0),所以正確是 m/2018'/5'/1'/0/1/0 為 path + '/0' console.log("---------------------------------------------") console.log("# PATH 是 m/2018'/5'/1'/0/1/0 因為底下為derive(0),所以 path + '/0' \n") console.log("privateKey (WIF): %o 符合", PathNode.derive(0).toWIF()) // L5ccMER4KyRn6pY6amvrFAHacpEsKrH1eTjDNeWwgXMnqjSCUU6N 符合 console.log("privateKey (Buffer): %o", PathNode.derive(0).privateKey) console.log("privateKey (String): %o", PathNode.derive(0).privateKey.toString()) console.log("privateKey (Hex): %o", PathNode.derive(0).privateKey.toString('hex')) console.log("privatekeyHex: %o \n", PathNode.derive(0).privkeyHex) console.log("publicKey (Hex): %o 符合", PathNode.derive(0).publicKey.toString('hex')) //024ac10a81e3a0f86cb4dad68c6a26031d805a057f36048f80a5b91b1c2cb0588c 符合 console.log("Bitcoin Address: %o 符合", getAddress(PathNode.derive(0))) //1Gp8AuHiYyBixrvLkKtC4VDhxpvK8PmYEr 符合 console.log("--------------------------------------------- \n") console.log('\n-----elliptic Initial Start----- \n'); var ec = new EC('p256'); let keyPair = ec.keyFromPrivate("83CFCC6EF1864C3303A5F8DEF2540167CB2DFA5DD22BB8D197B396972525FD56") let pubKey = keyPair.getPublic(); console.log("pubKey: %o", pubKey) // https://github.com/kjur/jsrsasign/issues/394 // sha512('aaa') => d6f644b19812e97b5d871658d6d3400ecd4787faeb9b8990c1e7608288664be77257104a58d033bcf1a0e0945ff06468ebe53e2dff36e248424c7273117dac09 let msgHash = 'd6f644b19812e97b5d871658d6d3400ecd4787faeb9b8990c1e7608288664be7' let signatureBase64 = 'MEUCIBEcfv2o3UwqwV72CVuYi7HbjcoiuSQOULY5d+DuGt3UAiEAtoNrdNWvjfdz/vR6nPiD+RveKN5znBtYaIrRDp2K7Ks=' let signatureHex = Buffer.from(signatureBase64, 'base64').toString('hex'); let validSig = ec.verify(msgHash, signatureHex, pubKey); console.log("Signature valid? %o \n", validSig); // use json var ec = new EC('secp256k1'); keyPair = ec.keyFromPrivate(dkey.publicKey) pubKey = keyPair.getPublic(); console.log("pubKey: %o", pubKey) var signature = keyPair.sign(json); var derSign = signature.toDER(); //console.log("signature: %o", signature) console.log("json verify: %o", keyPair.verify(json, derSign)); console.log('\n-----elliptic ed25519 Start----- \n'); var EdDSA = require('elliptic').eddsa var ec2 = new EdDSA('ed25519'); var ec2keypair = ec2.keyFromSecret(dkey.privateKey) //console.log("key: %o", key) var signature = ec2keypair.sign(json).toHex(); console.log("signature: %o", signature) var privateKeyHex = new Buffer(ec2keypair.getSecret()).toString('hex') var publickeyHex = new Buffer(ec2keypair.getPublic()).toString('hex') console.log("private key hex: %o", privateKeyHex) console.log("public key hex: %o", publickeyHex) var ec2keypair2 = ec2.keyFromPublic(publickeyHex, 'hex'); console.log("EdDSA json verify: %o", ec2keypair2.verify(json, signature)); bip39.mnemonicToSeed(mnemonic).then((vseed)=>{ var root = bitcoinSecp256r1.bip32.fromSeed(vseed) var PathNode = root.derivePath(path) console.log("bitcoinSecp256r1 privateKey (Hex): %o", PathNode.derive(0).privateKey.toString('hex')) console.log("bitcoinSecp256r1 publicKey (Hex): %o", PathNode.derive(0).publicKey.toString('hex')) const buf = Buffer.allocUnsafe(32); new Buffer.from(msgHash).copy(buf, 0, 0, 32) //msgbuf32 = new Buffer("01234567890123456789012345678901") console.log("msgHash buf 32: %o", buf.toString("hex")) var ecPair = bitcoinSecp256r1.ECPair.fromPrivateKey(PathNode.derive(0).privateKey) var signstring = ecPair.sign(buf) console.log("signstring: %o", signstring.toString("hex")) var verifyresult = ecPair.verify(buf, signstring) console.log("verify: %o", verifyresult) }) }) DeriveKey(mnemonic, path, type).then((v)=>{ console.log("dkey: %o", v) }); function getAddress (node, network) { return bitcoinSecp256r1.payments.p2pkh({ pubkey: node.publicKey, network }).address } function getEthereumAddress(privkeyHex) { const hexAddress = ethUtil.privateToAddress(Buffer.from(privkeyHex, 'hex')).toString('hex') const checksumAddress = ethUtil.toChecksumAddress(hexAddress) return checksumAddress } function DeriveKey(mnemonic, derivePath, type) { switch (type) { case "secp256r1": if (bip39.validateMnemonic(mnemonic)) { console.log("mnemonic is fake!") } return bip39.mnemonicToSeed(mnemonic).then((vseed)=>{ var root = bip32.fromSeed(vseed) var PathNode = root.derivePath(derivePath) console.log("# PATH 是 m/2018'/5'/1'/0/1/0 因為底下為derive(0),所以 path + '/0' \n") console.log("privateKey (Hex): %o", PathNode.derive(0).privateKey.toString('hex')) console.log("publicKey (Hex): %o 符合", PathNode.derive(0).publicKey.toString('hex')) // 024ac10a81e3a0f86cb4dad68c6a26031d805a057f36048f80a5b91b1c2cb0588c 符合 const buf = Buffer.allocUnsafe(32); PathNode.derive(0).privateKey.copy(buf, 0, 0, 32) console.log("Ethereum Address: %o 符合", getEthereumAddress(buf.toString('hex')) ) // 0xe020343a09086F53a203c9A0Ea76010049399575 符合 return { pub_buf: PathNode.derive(0).publicKey, wif: PathNode.derive(0).toWIF(), publicKey: PathNode.derive(0).publicKey.toString('hex'), privateKey: PathNode.derive(0).privateKey.toString('hex'), ethAddress: getEthereumAddress(buf.toString('hex')), path: derivePath } }).catch((e) => { console.log('handle error here: ', e.message) }) break; default: throw "type should be secp256k1 or secp256r1"; } }

2019-10-03 · 3 min · 492 words · Me

smart contract storage struct 未初始化 直接使用問題

https://github.com/knownsec/Ethereum-Smart-Contracts-Security-CheckList/blob/master/%E4%BB%A5%E5%A4%AA%E5%9D%8A%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6%E5%AE%A1%E8%AE%A1CheckList.md#11-%E6%9C%AA%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E5%82%A8%E5%AD%98%E6%8C%87%E9%92%88 https://www.chaindd.com/3102377.html https://blog.b9lab.com/storage-pointers-in-solidity-7dcfaa536089 https://medium.com/loom-network/ethereum-solidity-memory-vs-storage-how-to-initialize-an-array-inside-a-struct-184baf6aa2eb Use delete or new

2019-09-26 · 1 min · 8 words · Me

web3 deploy smart contract 1.2.1

Use https://remix.ethereum.org Get Contract json and data. In remix website, Compile finish. See Compliation Details. 1. ABI: click ABI buttion, get data. Use http://jsonviewer.stack.hu/ remove space 2. Compliation Details -> WEB3DEPLOY -> get data 3. cContract.options.from need put correct. var Web3 = require("web3"); var provider = new Web3.providers.HttpProvider("http://ganache:8545"); var web3 = new Web3(provider); //abi var cContract = new web3.eth.Contract([{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]) //bytecode cContract.options.data = '0x608060405234801561001057600080fd5b5060bf8061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b18114604d5780636d4ce63c146064575b600080fd5b348015605857600080fd5b5060626004356088565b005b348015606f57600080fd5b506076608d565b60408051918252519081900360200190f35b600055565b600054905600a165627a7a72305820765480c908e5e28e3233e18bfa422944b42cad5fc08b77d7b22d3ddd7016a1380029' cContract.options.from = '0xoooxxxoooxxxoooxxxoooxxxoooxxx' cContract.options.gas = '4700000' console.log("web3 version: %o", web3.version) web3.eth.getAccounts().then(o=>{console.log(o)}) cContract.deploy().send() .on('error', (error) => { console.log("error: %o", error) }) .on('transactionHash', (transactionHash) => { console.log("transactionHash: %o", transactionHash) }) .on('receipt', (receipt) => { // receipt will contain deployed contract address console.log("receipt: %o", receipt) console.log("receipt.contractAddress: %o", receipt.contractAddress) }) .on('confirmation', (confirmationNumber, receipt) => { console.log("confirmationNumber: %o", confirmationNumber) console.log("confirmation receipt: %o", receipt) }) .then(function(newContractInstance){ if (typeof newContractInstance.options.address !== 'undefined') { console.log('Contract mined! address: ' + newContractInstance.options.address); }else{ console.log("newContractInstance.address is undefined!") } });

2019-09-26 · 1 min · 141 words · Me

HDWalletProvider web3 smart contract connection need to stop or pool

HDWalletProvider engine.stop() p = HDWalletProvider(MNEMONIC_SYSTEM, "http://ganache:8545", 0); p.engine.stop(); HDWalletProvider engine.stop() and pool export function GetHdProvider(id: number, rpcurl: string) { //return new HDWalletProvider(MNEMONIC_SYSTEM, url, id); return id==0?Provider1Pool.acquire():Provider2Pool.acquire(); } // Normal use const hdProvider0 = await GetHdProvider(0, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); const hdProvider1 = await GetHdProvider(1, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); // Normal release ReleaseHDProvider1(hdProvider1 ); // Pool code const genericPool = require("generic-pool"); const opts = { max: 10, // maximum size of the pool min: 2, // minimum size of the pool idleTimeoutMillis: 30000, log: true }; const factory0 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 0); }, destroy: function(client) { client.engine.stop(); } }; const factory1 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 1); }, destroy: function(client) { client.engine.stop(); } }; export function ReleaseHDProvider1(client){ Provider1Pool.release(client); console.log("Provider1Pool status: pool.size %o pool.available %o pool.pending %o", Provider1Pool.size, Provider1Pool.available, Provider1Pool.pending) } export function ReleaseHDProvider2(client){ Provider2Pool.release(client); console.log("Provider2Pool status: pool.size %o pool.available %o pool.pending %o", Provider2Pool.size, Provider2Pool.available, Provider2Pool.pending) } const Provider1Pool = genericPool.createPool(factory0, opts); const Provider2Pool = genericPool.createPool(factory1, opts);

2019-09-25 · 1 min · 179 words · Me