aboutsummaryrefslogtreecommitdiffstats
path: root/les/backend.go
Commit message (Collapse)AuthorAgeFilesLines
* consensus, miner: stale block mining support (#17506)gary rong2018-08-281-1/+1
| | | | | | | | | | * consensus, miner: stale block supporting * consensus, miner: refactor seal signature * cmd, consensus, eth: add miner noverify flag * cmd, consensus, miner: polish
* all: make indexer configurable (#17188)gary rong2018-08-281-6/+7
|
* cmd, eth, miner: make recommit configurable (#17444)gary rong2018-08-221-1/+1
| | | | | | | | | | | | * cmd, eth, miner: make recommit configurable * cmd, eth, les, miner: polish a bit * miner: filter duplicate sealing work * cmd: remove uncessary conversion * miner: avoid microptimization in favor of cleaner code
* les: fix crasher in NodeInfo when running as server (#17419)Felix Lange2018-08-171-25/+23
| | | | | | | | | | | | | | | | | * les: fix crasher in NodeInfo when running as server The ProtocolManager computes CHT and Bloom trie roots by asking the indexers for their current head. It tried to get the indexers from LesOdr, but no LesOdr instance is created in server mode. Attempt to fix this by moving the indexers, protocol creation and NodeInfo to a new lesCommons struct which is embedded into both server and client. All this setup code should really be cleaned up, but this is just a hotfix so we have to do that some other time. * les: fix commons protocol maker
* light: CHT and bloom trie indexers working in light mode (#16534)Felföldi Zsolt2018-08-161-18/+21
| | | | | | | This PR enables the indexers to work in light client mode by downloading a part of these tries (the Merkle proofs of the last values of the last known section) in order to be able to add new values and recalculate subsequent hashes. It also adds CHT data to NodeInfo.
* cmd, consensus/ethash, eth: miner push notificationsPéter Szilágyi2018-08-101-1/+1
|
* consensus/ethash: move remote agent logic to ethash internal (#15853)gary rong2018-08-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | * consensus/ethash: start remote ggoroutine to handle remote mining * consensus/ethash: expose remote miner api * consensus/ethash: expose submitHashrate api * miner, ethash: push empty block to sealer without waiting execution * consensus, internal: add getHashrate API for ethash * consensus: add three method for consensus interface * miner: expose consensus engine running status to miner * eth, miner: specify etherbase when miner created * miner: commit new work when consensus engine is started * consensus, miner: fix some logics * all: delete useless interfaces * consensus: polish a bit
* les: pass server pool to protocol manager (#16947)Felföldi Zsolt2018-06-121-1/+1
|
* core/rawdb: separate raw database access to own package (#16666)Péter Szilágyi2018-05-071-1/+2
|
* les: limit LES peer count and improve peer configuration logic (#16010)Felföldi Zsolt2018-02-051-1/+4
| | | | | | * les: limit number of LES connections * eth, cmd/utils: light vs max peer configuration logic
* p2p, p2p/discover, p2p/discv5: implement UDP port sharing (#15200)Felföldi Zsolt2018-01-221-3/+2
| | | | | | | | | | | | | | | This commit affects p2p/discv5 "topic discovery" by running it on the same UDP port where the old discovery works. This is realized by giving an "unhandled" packet channel to the old v4 discovery packet handler where all invalid packets are sent. These packets are then processed by v5. v5 packets are always invalid when interpreted by v4 and vice versa. This is ensured by adding one to the first byte of the packet hash in v5 packets. DiscoveryV5Bootnodes is also changed to point to new bootnodes that are implementing the changed packet format with modified hash. Existing and new v5 bootnodes are both running on different ports ATM.
* cmd, consensus, eth: split ethash related config to it own (#15520)gary rong2017-11-241-1/+1
| | | | | | | | | | * cmd, consensus, eth: split ethash related config to it own * eth, consensus: minor polish * eth, consenus, console: compress pow testing config field to single one * consensus, eth: document pow mode
* les, core/bloombits: post-LES/2 fixes (#15391)Felföldi Zsolt2017-10-271-1/+1
| | | | | | * les: fix topic ID * core/bloombits: fix interface conversion
* les, light: LES/2 protocol version (#14970)Felföldi Zsolt2017-10-241-24/+55
| | | | | | | | | | | | | | | | | | This PR implements the new LES protocol version extensions: * new and more efficient Merkle proofs reply format (when replying to a multiple Merkle proofs request, we just send a single set of trie nodes containing all necessary nodes) * BBT (BloomBitsTrie) works similarly to the existing CHT and contains the bloombits search data to speed up log searches * GetTxStatusMsg returns the inclusion position or the pending/queued/unknown state of a transaction referenced by hash * an optional signature of new block data (number/hash/td) can be included in AnnounceMsg to provide an option for "very light clients" (mobile/embedded devices) to skip expensive Ethash check and accept multiple signatures of somewhat trusted servers (still a lot better than trusting a single server completely and retrieving everything through RPC). The new client mode is not implemented in this PR, just the protocol extension.
* core, light: send chain events using event.Feed (#14865)Miya Chen2017-08-181-2/+2
|
* les: fix megacheck warnings (#14941)Felföldi Zsolt2017-08-091-2/+1
| | | | | | * les: fix megacheck warnings * les: fixed testGetProofs
* les: code refactoring (#14416)Felföldi Zsolt2017-06-211-12/+28
| | | | | | | | | | | | This commit does various code refactorings: - generalizes and moves the request retrieval/timeout/resend logic out of LesOdr (will be used by a subsequent PR) - reworks the peer management logic so that all services can register with peerSet to get notified about added/dropped peers (also gets rid of the ugly getAllPeers callback in requestDistributor) - moves peerSet, LesOdr, requestDistributor and retrieveManager initialization out of ProtocolManager because I believe they do not really belong there and the whole init process was ugly and ad-hoc
* cmd, eth, les, mobile: make networkid uint64 everywherePéter Szilágyi2017-04-251-3/+3
|
* cmd/utils, node: remove unused solc references and improve RPC config (#14324)bas-vk2017-04-131-5/+1
| | | | | Currently http cors and websocket origins are a comma separated string in the config object. These are replaced with string arrays that are more expressive in case of a config file.
* cmd/geth: add --config file flag (#13875)Felix Lange2017-04-121-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * p2p/discover, p2p/discv5: add marshaling methods to Node * p2p/netutil: make Netlist decodable from TOML * common/math: encode nil HexOrDecimal256 as 0x0 * cmd/geth: add --config file flag * cmd/geth: add missing license header * eth: prettify Config again, fix tests * eth: use gasprice.Config instead of duplicating its fields * eth/gasprice: hide nil default from dumpconfig output * cmd/geth: hide genesis block in dumpconfig output * node: make tests compile * console: fix tests * cmd/geth: make TOML keys look exactly like Go struct fields * p2p: use discovery by default This makes the zero Config slightly more useful. It also fixes package node tests because Node detects reuse of the datadir through the NodeDatabase. * cmd/geth: make ethstats URL settable through config file * cmd/faucet: fix configuration * cmd/geth: dedup attach tests * eth: add comment for DefaultConfig * eth: pass downloader.SyncMode in Config This removes the FastSync, LightSync flags in favour of a more general SyncMode flag. * cmd/utils: remove jitvm flags * cmd/utils: make mutually exclusive flag error prettier It now reads: Fatal: flags --dev, -/* $Id$ */ #include "bbs.h" static int card_remain(int cards[]) { int i, temp = 0; for (i = 0; i < 52; i++) temp += cards[i]; if (temp == 52) return 1; return 0; } /* 0 Spare , 1 heart , ...3 dimon */ static int card_flower(int card) { return (card / 13); } /* 1...13 */ static int card_number(int card) { return (card % 13 + 1); } static int card_select(int *now) { char *cc[2] = {"\033[44m \033[m", "\033[1;33;41m △ \033[m"}; while (1) { move(20, 0); clrtoeol(); prints("%s%s%s%s%s", (*now == 0) ? cc[1] : cc[0], (*now == 1) ? cc[1] : cc[0], (*now == 2) ? cc[1] : cc[0], (*now == 3) ? cc[1] : cc[0], (*now == 4) ? cc[1] : cc[0]); switch (igetch()) { case 'Q': case 'q': return 0; case '+': case ',': return 1; case '\r': return -1; case KEY_LEFT: *now = (*now + 4) % 5; break; case KEY_RIGHT: *now = (*now + 1) % 5; break; case '1': *now = 0; break; case '2': *now = 1; break; case '3': *now = 2; break; case '4': *now = 3; break; case '5': *now = 4; break; } } } static void card_display(int cline, int number, int flower, int show) { int color = 31; char *cn[13] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; if (flower == 0 || flower == 3) color = 36; if ((show < 0) && (cline > 1 && cline < 8)) prints("│\033[1;33;42m※※※※\033[m│"); else switch (cline) { case 1: prints("╭────╮"); break; case 2: prints("│* les: light client protocol and APIZsolt Felfoldi2016-11-091-0/+218
f (flower == 1) prints("│\033[1;%dm◢◣◢◣\033[m│", color); else prints("│\033[1;%dm ◢◣ \033[m│", color); break; case 4: if (flower == 1) prints("│\033[1;%dm████\033[m│", color); else if (flower == 3) prints("│\033[1;%dm◣██◢\033[m│", color); else prints("│\033[1;%dm◢██◣\033[m│", color); break; case 5: if (flower == 0) prints("│\033[1;%dm████\033[m│", color); else if (flower == 3) prints("│\033[1;%dm█◥◤█\033[m│", color); else prints("│\033[1;%dm◥██◤\033[m│", color); break; case 6: if (flower == 0) prints("│\033[1;%dm ◢◣ \033[m│", color); else if (flower == 3) prints("│\033[1;%dm◥◢◣◤\033[m│", color); else prints("│\033[1;%dm ◥◤ \033[m│", color); break; case 7: prints("│ \033[1;%dm%s\033[m│", color, cn[number - 1]); break; case 8: prints("╰────╯"); break; } } static void card_show(int cpu[], int c[], int me[], int m[]) { int i, j; for (j = 0; j < 8; j++) { move(2 + j, 0); clrtoeol(); for (i = 0; i < 5 && cpu[i] >= 0; i++) card_display(j + 1, card_number(cpu[i]), card_flower(cpu[i]), c[i]); } for (j = 0; j < 8; j++) { move(11 + j, 0); clrtoeol(); for (i = 0; i < 5 && me[i] >= 0; i++) card_display(j + 1, card_number(me[i]), card_flower(me[i]), m[i]); } } static void card_new(int cards[]) { memset(cards, 0, sizeof(int) * 52); } static int card_give(int cards[]) { int i, error; for (error = 0, i = rand() % 52; cards[i] == 1 && error < 52; error++, i = rand() % 52); if (error == 52) card_new(cards); /* Ptt: 這邊有 dead lock 的問題 */ cards[i] = 1; return i; } static void card_start(char name[]) { clear(); stand_title(name); move(1, 0); prints(" \033[1;33;41m 電 腦 \033[m"); move(10, 0); prints("\033[1;34;44m◆~◆~◆~◆~◆~◆~◆~◆~◆~◆~◆~◆~" "◆~◆~◆~◆~◆~◆~◆~◆\033[m"); move(19, 0); prints(" \033[1;37;42m 自 己 \033[m"); } static int card_99_add(int i, int aom, int count) { if (i == 4 || i == 5 || i == 11) return count; else if (i == 12) return count + 20 * aom; else if (i == 10) return count + 10 * aom; else if (i == 13) return 99; else return count + i; } static int card_99_cpu(int cpu[], int *count) { int stop = -1; int twenty = -1; int ten = -1; int kill = -1; int temp, num[10]; int other = -1; int think = 99 - (*count); int i, j; for (i = 0; i < 10; i++) num[i] = -1; for (i = 0; i < 5; i++) { temp = card_number(cpu[i]); if (temp == 4 || temp == 5 || temp == 11) stop = i; else if (temp == 12) twenty = i; else if (temp == 10) ten = i; else if (temp == 13) kill = i; else { other = i; num[temp] = i; } } for (j = 9; j > 0; j--) if (num[j] >= 0 && j != 4 && j != 5 && think >= j) { (*count) += j; return num[j]; } if ((think >= 20) && (twenty >= 0)) { (*count) += 20; return twenty; } else if ((think >= 10) && (ten >= 0)) { (*count) += 10; return ten; } else if (stop >= 0) return stop; else if (kill >= 0) { (*count) = 99; return kill; } else if (ten >= 0) { (*count) -= 10; return ten; } else if (twenty >= 0) { (*count) -= 20; return twenty; } else { (*count) += card_number(cpu[0]); return 0; } } int card_99() { int i, j, turn; int cpu[5], c[5], me[5], m[5]; int cards[52]; int count = 0; char *ff[4] = {"\033[1;36m黑桃", "\033[1;31m紅心", "\033[1;31m方塊", "\033[1;36m黑花"}; char *cn[13] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; for (i = 0; i < 5; i++) cpu[i] = c[i] = me[i] = m[i] = -1; setutmpmode(CARD_99); card_start("天長地久"); card_new(cards); for (i = 0; i < 5; i++) { cpu[i] = card_give(cards); me[i] = card_give(cards); m[i] = 1; } card_show(cpu, c, me, m); j = 0; turn = 1; move(21, 0); clrtoeol(); prints("[0]目前 %d , 殘 %d \n", count, 99 - count); prints("左右鍵移動游標, [Enter]確定, [ + ]表加二十(加十), [Q/q]放棄遊戲"); while (1) { i = card_select(&j); if (i == 0) /* 放棄遊戲 */ return 0; count = card_99_add(card_number(me[j]), i, count); move(21 + (turn / 2) % 2, 0); clrtoeol(); prints("[%d]您出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", turn, ff[card_flower(me[j])], cn[card_number(me[j]) - 1], count, 99 - count); me[j] = card_give(cards); turn++; if (count < 0) count = 0; card_show(cpu, c, me, m); pressanykey(); if (count > 99) { move(22, 0); clrtoeol(); prints("[%d]結果..YOU LOSS..目前 \033[1;31m%d/\033[34m%d\033[m 點", turn, count, 99 - count); pressanykey(); return 0; } i = card_99_cpu(cpu, &count); move(21 + (turn / 2 + 1) % 2, 40); prints("[%d]電腦出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", turn, ff[card_flower(cpu[i])], cn[card_number(cpu[i]) - 1], count, 99 - count); cpu[i] = card_give(cards); turn++; if (count < 0) count = 0; if (count > 99) { move(22, 0); clrtoeol(); prints("[%d]結果..YOU WIN!..目前 \033[1;31m%d/\033[34m%d\033[m 點", turn, count, 99 - count); pressanykey(); return 0; } if (!card_remain(cards)) { card_new(cards); for (i = 0; i < 5; i++) { cards[me[i]] = 1; cards[cpu[i]] = 1; } } } } #define PMONEY (10) #define TEN_HALF (5) /* 十點半的Ticket */ #define JACK (10) /* 黑傑克的Ticket */ #define NINE99 (99) /* 99 的Ticket */ static int game_log(int type, int money) { FILE *fp; if (money > 0) demoney(money); switch (type) { case JACK: fp = fopen(BBSHOME "/etc/card/jack.log", "a"); if (!fp) return 0; fprintf(fp, "%s win:%d\n", cuser.userid, money); fclose(fp); break; case TEN_HALF: fp = fopen(BBSHOME "/etc/card/tenhalf.log", "a"); if (!fp) return 0; fprintf(fp, "%s win:%d\n", cuser.userid, money); fclose(fp); break; } return 0; } static int card_double_ask() { char buf[100], buf2[3]; snprintf(buf, sizeof(buf), "[ %s ]您現在共有 %d P幣, 現在要分組(加收 %d 元)嗎? [y/N]", cuser.userid, cuser.money, JACK); reload_money(); if (cuser.money < JACK) return 0; getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); if (buf2[0] == 'y' || buf2[0] == 'Y') return 1; return 0; } static int card_ask() { char buf[100], buf2[3]; snprintf(buf, sizeof(buf), "[ %s ]您現在共有 %d P幣, 還要加牌嗎? [y/N]", cuser.userid, cuser.money); getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); if (buf2[0] == 'y' || buf2[0] == 'Y') return 1; return 0;