mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
Compare commits
1314 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb49457ff2 | ||
|
|
1d1f32d16d | ||
|
|
de038acd96 | ||
|
|
673021410f | ||
|
|
cf64347d70 | ||
|
|
0a5ce30bc1 | ||
|
|
de2b9459bd | ||
|
|
b855abb8db | ||
|
|
56caa38a67 | ||
|
|
d0b3e77a08 | ||
|
|
eed1785f70 | ||
|
|
8d5f461cb6 | ||
|
|
c2bb42168b | ||
|
|
e4954b1297 | ||
|
|
ada2a39691 | ||
|
|
43de64949c | ||
|
|
ee0b648536 | ||
|
|
a6be58d536 | ||
|
|
39930ca6ae | ||
|
|
cac6b389d1 | ||
|
|
285746d3db | ||
|
|
738835d7b8 | ||
|
|
61fd72695f | ||
|
|
c0b130b79b | ||
|
|
81bbef2609 | ||
|
|
366944431b | ||
|
|
f1e262c8e1 | ||
|
|
bb353618f1 | ||
|
|
0547b02af7 | ||
|
|
d2cc6f489c | ||
|
|
da6e9fe634 | ||
|
|
827d8c2e0c | ||
|
|
d210f4f5b8 | ||
|
|
bcc292b22d | ||
|
|
00a757375c | ||
|
|
02247490f6 | ||
|
|
d6b13283d1 | ||
|
|
1bf66fcc0a | ||
|
|
31a8b70ee3 | ||
|
|
2a739598b1 | ||
|
|
9c8dc7caf1 | ||
|
|
c8bf315188 | ||
|
|
018ec85ff7 | ||
|
|
f72fd0e792 | ||
|
|
a5ba586669 | ||
|
|
552af52b45 | ||
|
|
3b2eb49db9 | ||
|
|
3e37e7eca4 | ||
|
|
2e3ffb2d82 | ||
|
|
842a31ad1b | ||
|
|
50e01ee620 | ||
|
|
035cb4781d | ||
|
|
fee10d800e | ||
|
|
14ac0adcc7 | ||
|
|
189eb6a989 | ||
|
|
5a1a362215 | ||
|
|
95d7f00295 | ||
|
|
1381ad2b21 | ||
|
|
26809acbf9 | ||
|
|
4d369ec30c | ||
|
|
f5cb3488be | ||
|
|
dc2a68dc43 | ||
|
|
6a34def27e | ||
|
|
1a52dd10a7 | ||
|
|
6ca5ee6211 | ||
|
|
b202d43076 | ||
|
|
22f9b06903 | ||
|
|
52c90a2b2b | ||
|
|
93dd68e924 | ||
|
|
feec18e329 | ||
|
|
49b09ec04f | ||
|
|
3731f5788e | ||
|
|
ea9eaf9dec | ||
|
|
2f91373a0a | ||
|
|
807f3e83ba | ||
|
|
bb86cffa56 | ||
|
|
e1eb3d4451 | ||
|
|
f394f21594 | ||
|
|
0eaaa83ba5 | ||
|
|
38682648c2 | ||
|
|
1da09ab062 | ||
|
|
d6c4400d57 | ||
|
|
da9413d913 | ||
|
|
81605d90f5 | ||
|
|
e96a8c7d86 | ||
|
|
3ccbaa56f4 | ||
|
|
1ba4925755 | ||
|
|
2dca98511f | ||
|
|
f2b066da70 | ||
|
|
bfc24bd4ce | ||
|
|
6cbae37667 | ||
|
|
b1d3e95a0a | ||
|
|
ea0796bde3 | ||
|
|
8b371316c5 | ||
|
|
8f09e4cac4 | ||
|
|
f8c449b5c8 | ||
|
|
085d9c75f4 | ||
|
|
a0971337d0 | ||
|
|
5add0b0d0f | ||
|
|
7fddf1210e | ||
|
|
463a1cab43 | ||
|
|
0a4e67afad | ||
|
|
b3295cd283 | ||
|
|
c1d79812f4 | ||
|
|
d078739965 | ||
|
|
8b1eb5687d | ||
|
|
a21bdda7ad | ||
|
|
3b3d999618 | ||
|
|
ac4e7f6269 | ||
|
|
ab91bf39b7 | ||
|
|
17f8d6e400 | ||
|
|
76970091f1 | ||
|
|
62904b33f3 | ||
|
|
0e08efc54a | ||
|
|
b019ea17ec | ||
|
|
963af6449f | ||
|
|
b0a90fbb0c | ||
|
|
eabc8f2c81 | ||
|
|
d8ecd21ff7 | ||
|
|
23a44a7ad6 | ||
|
|
85eb1e7e56 | ||
|
|
31fac119dc | ||
|
|
4ee706243c | ||
|
|
da7b8c1260 | ||
|
|
5cb01b5714 | ||
|
|
2dc953274d | ||
|
|
db1967957d | ||
|
|
7b1504ccb8 | ||
|
|
f875921176 | ||
|
|
af8c050bff | ||
|
|
b9a4aaad1e | ||
|
|
f106491fa2 | ||
|
|
1913b6e2fc | ||
|
|
3c28b335af | ||
|
|
004fa1441c | ||
|
|
4dc89fa875 | ||
|
|
97e02a8d52 | ||
|
|
65786afb05 | ||
|
|
1fcebc16c5 | ||
|
|
ace35a1997 | ||
|
|
4bd34b4966 | ||
|
|
2387944782 | ||
|
|
8788221761 | ||
|
|
aeea5e2a2d | ||
|
|
91c218a1cb | ||
|
|
21327ebe93 | ||
|
|
32416e380b | ||
|
|
4f76be1dc5 | ||
|
|
e271c1d3d0 | ||
|
|
b930a2a6be | ||
|
|
274b7ab123 | ||
|
|
8d367c7e66 | ||
|
|
42613c97d5 | ||
|
|
dcb14198bb | ||
|
|
38e8f282d2 | ||
|
|
2fd6f067db | ||
|
|
bec02998b4 | ||
|
|
8c7b6c05db | ||
|
|
9d7da11458 | ||
|
|
acbe4a1f32 | ||
|
|
89fbd1f11c | ||
|
|
9c80909452 | ||
|
|
eaf00a3a5d | ||
|
|
4d0c2b6cf4 | ||
|
|
ddb709e9de | ||
|
|
0e1be81a4a | ||
|
|
016178132e | ||
|
|
0689a7eb9c | ||
|
|
90489ae977 | ||
|
|
9c94bdac06 | ||
|
|
ddbddcb31e | ||
|
|
b5c1467a7d | ||
|
|
576b5efe93 | ||
|
|
c2cd13faa4 | ||
|
|
d93e5986d7 | ||
|
|
f78fd6f397 | ||
|
|
a65b53bf06 | ||
|
|
c3856bb011 | ||
|
|
a4d4403a75 | ||
|
|
4d1d94c56c | ||
|
|
4445434a2d | ||
|
|
61d8507140 | ||
|
|
382e9e25ff | ||
|
|
74d36d44f2 | ||
|
|
5fc3a0f707 | ||
|
|
6117afeeaa | ||
|
|
c7df832d7a | ||
|
|
1b4bd4c976 | ||
|
|
fc52af2736 | ||
|
|
29316f7bd0 | ||
|
|
3f37f20ddc | ||
|
|
e273c51287 | ||
|
|
6a60c64c6b | ||
|
|
3595b18793 | ||
|
|
5f38875807 | ||
|
|
af4da4be3d | ||
|
|
3588c91c7e | ||
|
|
286dbba2d2 | ||
|
|
f35c6c4fb9 | ||
|
|
9eb7fc5842 | ||
|
|
06707dd610 | ||
|
|
9c63fd8e76 | ||
|
|
8ef51cf15c | ||
|
|
41b2856bd4 | ||
|
|
e598b5b5c2 | ||
|
|
0d9556f948 | ||
|
|
4f6a85b3bd | ||
|
|
0eeb54cb89 | ||
|
|
ba7ba84f07 | ||
|
|
f29eaee30a | ||
|
|
03fa53a640 | ||
|
|
a1755ec426 | ||
|
|
fde5c34bd8 | ||
|
|
ef8e821cf2 | ||
|
|
8cd98a9a26 | ||
|
|
ea2fda46c3 | ||
|
|
028ec224b8 | ||
|
|
d0377a70e2 | ||
|
|
1837696580 | ||
|
|
d5a52d9b3e | ||
|
|
772351b0d5 | ||
|
|
9db9642db4 | ||
|
|
b9c078ea96 | ||
|
|
8f3f554053 | ||
|
|
12324c1693 | ||
|
|
bc8d832335 | ||
|
|
382b75f528 | ||
|
|
af1c6b93b7 | ||
|
|
9fd537965d | ||
|
|
65ce215641 | ||
|
|
c68c4bc7a4 | ||
|
|
b1093efa83 | ||
|
|
f09e8fcd33 | ||
|
|
bdab0cf58c | ||
|
|
0050cf21ce | ||
|
|
e07c8e9123 | ||
|
|
1bcd3f26c0 | ||
|
|
9655d73f49 | ||
|
|
45beb88966 | ||
|
|
e422bebbdc | ||
|
|
579d011738 | ||
|
|
05fa0de6d8 | ||
|
|
92735bca31 | ||
|
|
22dfd73598 | ||
|
|
47753fa369 | ||
|
|
c3f95ef13f | ||
|
|
bdbfd2329a | ||
|
|
9c7722b7c5 | ||
|
|
cf78183fad | ||
|
|
de363e73ea | ||
|
|
331544bc37 | ||
|
|
b765385a3e | ||
|
|
0b886ad1bd | ||
|
|
e95568b78d | ||
|
|
fedd060d81 | ||
|
|
a159d6caf0 | ||
|
|
4942b21203 | ||
|
|
ba1cdb6883 | ||
|
|
d9725378b0 | ||
|
|
f161a2c211 | ||
|
|
1a3dcca8f4 | ||
|
|
80cfc3a485 | ||
|
|
f39ab4c8d0 | ||
|
|
5c88e3c108 | ||
|
|
1954d40691 | ||
|
|
0e1d3551da | ||
|
|
cd58f05894 | ||
|
|
b4b7ed1915 | ||
|
|
5f2b41d54d | ||
|
|
c625ae04d2 | ||
|
|
e3bc569865 | ||
|
|
143acc7672 | ||
|
|
4a4a0c1196 | ||
|
|
a483c27704 | ||
|
|
a2168d94c0 | ||
|
|
7600e7fc39 | ||
|
|
ddd1ffb4f1 | ||
|
|
79f2525ab6 | ||
|
|
cc6dfd1f4b | ||
|
|
b86da2abe8 | ||
|
|
af3b5ea569 | ||
|
|
d5e7b61173 | ||
|
|
da9e86c3b6 | ||
|
|
fc4743faa8 | ||
|
|
336a0abbbb | ||
|
|
4d51be1cf3 | ||
|
|
d18f2fd9d6 | ||
|
|
de237cbfa4 | ||
|
|
3fcec0d4a0 | ||
|
|
b3a570d158 | ||
|
|
89a7bd644f | ||
|
|
30c8a40847 | ||
|
|
221497c61b | ||
|
|
8e2ebc0106 | ||
|
|
8765d20b1e | ||
|
|
10ffb45667 | ||
|
|
8555a3e3cc | ||
|
|
a108d3defb | ||
|
|
dabb95b892 | ||
|
|
63046fcf62 | ||
|
|
2d914f89fe | ||
|
|
1e7027b41e | ||
|
|
746f502a79 | ||
|
|
4b94f4e0ed | ||
|
|
0825aee8f4 | ||
|
|
a55ed9d5bb | ||
|
|
14486dc0e2 | ||
|
|
b2ce93fe16 | ||
|
|
c23b6fd688 | ||
|
|
198947c19f | ||
|
|
765654dae8 | ||
|
|
2c006b0b3e | ||
|
|
c5f90cd88b | ||
|
|
3a50cd2193 | ||
|
|
c995995eb8 | ||
|
|
2bc15836be | ||
|
|
319236afa2 | ||
|
|
026594e269 | ||
|
|
dc1e5ad191 | ||
|
|
3557f99cf5 | ||
|
|
3d88c9b4d3 | ||
|
|
44427fa833 | ||
|
|
3390014fd0 | ||
|
|
dd199d0ebd | ||
|
|
88bd012003 | ||
|
|
efdcf94174 | ||
|
|
381e87cbd2 | ||
|
|
4aaa4313e7 | ||
|
|
75578d60f3 | ||
|
|
68acc1b4cb | ||
|
|
8ce7915aad | ||
|
|
1be064190e | ||
|
|
f81e6f779b | ||
|
|
ffe47d6d5d | ||
|
|
0f460644e3 | ||
|
|
b49f1398a1 | ||
|
|
3c726dd3c0 | ||
|
|
814efd6f1f | ||
|
|
e6bc9c35f3 | ||
|
|
06e0e1c853 | ||
|
|
b5029b87c8 | ||
|
|
a823faecf1 | ||
|
|
0ecbd46fe7 | ||
|
|
05a85b2b38 | ||
|
|
3c83387c29 | ||
|
|
c1aed4eff4 | ||
|
|
6986c779f0 | ||
|
|
2e53709f17 | ||
|
|
a9d811a976 | ||
|
|
e0e54740b1 | ||
|
|
c555400ca1 | ||
|
|
29c8fb0d93 | ||
|
|
986a78979e | ||
|
|
701e1f5254 | ||
|
|
ebeafe5b0b | ||
|
|
c32ad4594e | ||
|
|
6892cb056d | ||
|
|
50c85be6fc | ||
|
|
f00ffc6c00 | ||
|
|
f5a3dbea40 | ||
|
|
2acfa219aa | ||
|
|
64c0020ff8 | ||
|
|
6fe375c3bd | ||
|
|
12e5881c09 | ||
|
|
26227db843 | ||
|
|
951f7d35d6 | ||
|
|
0bf30d2b33 | ||
|
|
90d95b6323 | ||
|
|
1376a542b4 | ||
|
|
fa914f1dda | ||
|
|
a7f82808c4 | ||
|
|
a76552ce47 | ||
|
|
134cb634b1 | ||
|
|
1d915d0237 | ||
|
|
e3132693fa | ||
|
|
100f189c25 | ||
|
|
4b76541c25 | ||
|
|
f00a0dcfed | ||
|
|
07becec31c | ||
|
|
1854433829 | ||
|
|
5f2e4b0565 | ||
|
|
e47bd0195c | ||
|
|
c93236b564 | ||
|
|
3c3666d67e | ||
|
|
18871d4785 | ||
|
|
ce2f66d9bf | ||
|
|
d67badd9ce | ||
|
|
ab0d6428b1 | ||
|
|
d47afc7f4c | ||
|
|
c95d9a9482 | ||
|
|
41c938eede | ||
|
|
ce652affe0 | ||
|
|
14ad993895 | ||
|
|
92f6fb4cfa | ||
|
|
36fe96581f | ||
|
|
b277b0f100 | ||
|
|
304ca95508 | ||
|
|
9f46ab62b1 | ||
|
|
96931d6f78 | ||
|
|
f04f24503d | ||
|
|
1c009d622d | ||
|
|
6cc409c24b | ||
|
|
07f1bb0d60 | ||
|
|
1f915e418c | ||
|
|
1290914b37 | ||
|
|
d0c0706042 | ||
|
|
dbb0a12366 | ||
|
|
916b11fba5 | ||
|
|
b9a33a61a0 | ||
|
|
56d673675d | ||
|
|
81ccec4042 | ||
|
|
771ffb5e28 | ||
|
|
639b61d78e | ||
|
|
4a7d53ee23 | ||
|
|
144bfd9c53 | ||
|
|
a04030d30f | ||
|
|
45aa01fe89 | ||
|
|
3dbca25b69 | ||
|
|
dae7fff12e | ||
|
|
ff20f32338 | ||
|
|
e4b4f2d532 | ||
|
|
fd28283707 | ||
|
|
bc4fb165ea | ||
|
|
8e66454df9 | ||
|
|
b42adfe052 | ||
|
|
30d509c12e | ||
|
|
2e00b8fbd9 | ||
|
|
148e107da6 | ||
|
|
fbf99a9cdc | ||
|
|
232393e3bd | ||
|
|
4060d64fc9 | ||
|
|
ddadf791f1 | ||
|
|
ea53f183fc | ||
|
|
6ece1d747e | ||
|
|
c7441658da | ||
|
|
9af3c3c824 | ||
|
|
0e3947ef32 | ||
|
|
0ba5bacd0c | ||
|
|
b19811d5f4 | ||
|
|
249856d557 | ||
|
|
520198138a | ||
|
|
08492c952b | ||
|
|
9502ee3b5f | ||
|
|
5c83f797c5 | ||
|
|
2a919e396d | ||
|
|
dae3e10a5a | ||
|
|
47894585ae | ||
|
|
a75b45fcd3 | ||
|
|
6e3a1a3742 | ||
|
|
698b9f3095 | ||
|
|
50fc02d063 | ||
|
|
dab9fa7f91 | ||
|
|
b47d2bc164 | ||
|
|
6c83a8419b | ||
|
|
a2709fad7f | ||
|
|
899d373b3c | ||
|
|
34420d655d | ||
|
|
9a6ab7f142 | ||
|
|
fe70b09c42 | ||
|
|
8a05341cf5 | ||
|
|
24154ed64b | ||
|
|
31b581bcac | ||
|
|
f77654a0e9 | ||
|
|
96929a5515 | ||
|
|
c729dbb6d2 | ||
|
|
613389019e | ||
|
|
c6494d82fa | ||
|
|
3898609304 | ||
|
|
3ee48ba20a | ||
|
|
4d9c55da72 | ||
|
|
b7506b302d | ||
|
|
90c838da9f | ||
|
|
812392d325 | ||
|
|
467b79391f | ||
|
|
da1103f4f8 | ||
|
|
19521acfa4 | ||
|
|
18e8e43715 | ||
|
|
6d6c2afb2b | ||
|
|
3c3cb60a90 | ||
|
|
eca96d7118 | ||
|
|
7790f391ab | ||
|
|
b5ec1da9e9 | ||
|
|
eb9a21afed | ||
|
|
3a906d45dc | ||
|
|
ac8d2b1df7 | ||
|
|
0f5d4c6e88 | ||
|
|
1006f0707e | ||
|
|
a590aae017 | ||
|
|
e749405297 | ||
|
|
70ab73a008 | ||
|
|
5fa83965f2 | ||
|
|
1b71f82e38 | ||
|
|
460d878613 | ||
|
|
4e97a9d9eb | ||
|
|
7cf3d2ccb9 | ||
|
|
18c4beb05b | ||
|
|
7f1de3fec8 | ||
|
|
e75acc006e | ||
|
|
abbb9a829c | ||
|
|
6c88568fef | ||
|
|
4a52c187d3 | ||
|
|
9d6cd04b3b | ||
|
|
bcf0f41171 | ||
|
|
a95a0ab569 | ||
|
|
2943f60811 | ||
|
|
8a6ea5d687 | ||
|
|
3563824c60 | ||
|
|
82ec7d5542 | ||
|
|
2849d0661d | ||
|
|
1282c8653e | ||
|
|
160eb23b0e | ||
|
|
e4ebe82ee2 | ||
|
|
6cef700203 | ||
|
|
a8c20ea946 | ||
|
|
d887f54494 | ||
|
|
5b14622110 | ||
|
|
ad25804feb | ||
|
|
415a87ef36 | ||
|
|
817ee0d826 | ||
|
|
0ae2ac5431 | ||
|
|
983e4bdef0 | ||
|
|
3948eb0c54 | ||
|
|
d789a3f140 | ||
|
|
863e995b79 | ||
|
|
54ce3bad64 | ||
|
|
d077dd2a6e | ||
|
|
70f7f00385 | ||
|
|
d62a1947be | ||
|
|
d07eaba195 | ||
|
|
cb1fcde2f4 | ||
|
|
e6332751c6 | ||
|
|
25d5c19522 | ||
|
|
a3869547e5 | ||
|
|
e0be8da392 | ||
|
|
c4c99ade65 | ||
|
|
d89f06c1ae | ||
|
|
a08e182698 | ||
|
|
9700f212ad | ||
|
|
fdfdb5cd7d | ||
|
|
a3d12f445a | ||
|
|
b768a38b76 | ||
|
|
0783bcceef | ||
|
|
d65e959bae | ||
|
|
219abac227 | ||
|
|
70f6049f71 | ||
|
|
703db97d80 | ||
|
|
229c34f818 | ||
|
|
c283b3c569 | ||
|
|
451c3957fe | ||
|
|
16d5671943 | ||
|
|
4c6b210af0 | ||
|
|
0f5a2a82d9 | ||
|
|
c5532e188e | ||
|
|
7596a030c6 | ||
|
|
550c73f4c8 | ||
|
|
baf814f3da | ||
|
|
8b7b3be765 | ||
|
|
5204ca87e2 | ||
|
|
2bbfcd2d02 | ||
|
|
432d28d3bb | ||
|
|
896899e0d6 | ||
|
|
a54d2118be | ||
|
|
8ce04527f9 | ||
|
|
6062de265a | ||
|
|
3bbb49de55 | ||
|
|
e0873dafc5 | ||
|
|
07368a9e3c | ||
|
|
ad5f29b743 | ||
|
|
1d42878adb | ||
|
|
39471861d5 | ||
|
|
fab7858a35 | ||
|
|
194ea3186a | ||
|
|
c971112dfa | ||
|
|
c4971e24f9 | ||
|
|
1e8aeae15a | ||
|
|
7d72a8c36a | ||
|
|
d59bce21e5 | ||
|
|
641cfb1456 | ||
|
|
64d46e7c6a | ||
|
|
0f10b21719 | ||
|
|
f5f2d7410d | ||
|
|
93b7af3099 | ||
|
|
7a98f19fb6 | ||
|
|
d518e444f8 | ||
|
|
b5782531ad | ||
|
|
7d1490576d | ||
|
|
1bdc992a59 | ||
|
|
15094f7654 | ||
|
|
66654ab02e | ||
|
|
44c89996c8 | ||
|
|
c4443c2be1 | ||
|
|
c4879a0c2f | ||
|
|
609046df6a | ||
|
|
c17e60e270 | ||
|
|
992a2e2e79 | ||
|
|
d2e6dd6c99 | ||
|
|
d4b2f3c45b | ||
|
|
9b1732baae | ||
|
|
12718ce767 | ||
|
|
de29f9b444 | ||
|
|
e5ad8de2d9 | ||
|
|
2842fe4aa3 | ||
|
|
b6ef8d5a40 | ||
|
|
9247134eab | ||
|
|
993928cfcc | ||
|
|
59e0f445ce | ||
|
|
883a310904 | ||
|
|
b065976007 | ||
|
|
40d23dafb7 | ||
|
|
11f73c728a | ||
|
|
0ed0806bb4 | ||
|
|
1b7cd74a49 | ||
|
|
31ac53fbdc | ||
|
|
43346904e1 | ||
|
|
afdd59416e | ||
|
|
4d009243cb | ||
|
|
45268208ae | ||
|
|
618b250e34 | ||
|
|
b69dd08ae7 | ||
|
|
4e16306ae3 | ||
|
|
46e06b875d | ||
|
|
831f59ce8b | ||
|
|
d650f96d5f | ||
|
|
4ce190a015 | ||
|
|
e333ab56d5 | ||
|
|
9b0369c773 | ||
|
|
9f46a3e32a | ||
|
|
371f9616e9 | ||
|
|
2976a52222 | ||
|
|
8f6111bb9c | ||
|
|
882ba0e752 | ||
|
|
88d7bc930a | ||
|
|
1c85a7f3eb | ||
|
|
5d6b30271f | ||
|
|
8103b0bb62 | ||
|
|
98474d3d6f | ||
|
|
ea7582bb41 | ||
|
|
10b45b4c2e | ||
|
|
78e851f94f | ||
|
|
587f929c64 | ||
|
|
50fac68654 | ||
|
|
407e20c11a | ||
|
|
10ed8178fc | ||
|
|
e69a797990 | ||
|
|
f6521b66f7 | ||
|
|
a2bd31432f | ||
|
|
20cb17e1f9 | ||
|
|
3cd01fdf0e | ||
|
|
a52c7a1b65 | ||
|
|
1e07068adf | ||
|
|
c87c8cd163 | ||
|
|
248bceb30c | ||
|
|
feeb761ba0 | ||
|
|
4e6e3293ff | ||
|
|
325e5c3ef0 | ||
|
|
787f5e9949 | ||
|
|
8fdb7e108f | ||
|
|
fbf9df2ea3 | ||
|
|
7cc2ceae09 | ||
|
|
a0780ba08a | ||
|
|
43b6dafa6e | ||
|
|
c1ecab818c | ||
|
|
914dc01222 | ||
|
|
6b8a17119e | ||
|
|
1025440184 | ||
|
|
fd61d6f506 | ||
|
|
f04017f702 | ||
|
|
b92095f18c | ||
|
|
2ae4ad004a | ||
|
|
ec9c902133 | ||
|
|
bd09334d1a | ||
|
|
8e154e4d74 | ||
|
|
480d44bd0b | ||
|
|
429039d45d | ||
|
|
8956453c0d | ||
|
|
976c08b68a | ||
|
|
dbd9c486bb | ||
|
|
33d7d93298 | ||
|
|
41c6b8abc6 | ||
|
|
9ac282ca0c | ||
|
|
7a99821377 | ||
|
|
f9189543bf | ||
|
|
f29f242758 | ||
|
|
0134a1c08c | ||
|
|
5d0f7c4f47 | ||
|
|
fa638ec8af | ||
|
|
78eb2789b2 | ||
|
|
8fe791e4e2 | ||
|
|
f94b64c2f3 | ||
|
|
acf513cfe7 | ||
|
|
d1edab602a | ||
|
|
b06f9c1364 | ||
|
|
43d16f0361 | ||
|
|
d0e4051cd8 | ||
|
|
09cec19e2f | ||
|
|
eef7c4a773 | ||
|
|
ea591ead85 | ||
|
|
7b671f52e0 | ||
|
|
63407fd6e2 | ||
|
|
bc5053d93e | ||
|
|
ce7896070c | ||
|
|
25047eb3e9 | ||
|
|
7d80d2e3d7 | ||
|
|
3b9473afa2 | ||
|
|
ce4cc630c2 | ||
|
|
9c137aaccf | ||
|
|
46784d0826 | ||
|
|
6e86c4700b | ||
|
|
4dfbc78a88 | ||
|
|
5a8398e55a | ||
|
|
239c11d0dd | ||
|
|
0832c0d166 | ||
|
|
ab1b288fa7 | ||
|
|
fe4a655042 | ||
|
|
563f3efda3 | ||
|
|
6f3b919ae1 | ||
|
|
01ecb074a7 | ||
|
|
ffe8b77a61 | ||
|
|
94e34fa0ad | ||
|
|
8b1202c52c | ||
|
|
24b57e3c6a | ||
|
|
cd9696fc97 | ||
|
|
b52a270538 | ||
|
|
00fb08158d | ||
|
|
cde87ee75c | ||
|
|
bd795bd543 | ||
|
|
973ca019bc | ||
|
|
23e5c5b11a | ||
|
|
e3f72a3555 | ||
|
|
8a6a35e9d9 | ||
|
|
394b9298fa | ||
|
|
29875dcb4b | ||
|
|
9af080c351 | ||
|
|
fea25712ca | ||
|
|
ff0ee876bb | ||
|
|
d6615a54c6 | ||
|
|
660ff174f2 | ||
|
|
62922c8ab0 | ||
|
|
4add41a2a6 | ||
|
|
7a15109c04 | ||
|
|
77b99cf7ad | ||
|
|
3a25a2b9b0 | ||
|
|
a3b4caac38 | ||
|
|
4a9130aca2 | ||
|
|
320fe1015a | ||
|
|
47f48a658d | ||
|
|
6d64a0bfed | ||
|
|
6c513a45d5 | ||
|
|
f9dd136a09 | ||
|
|
c0a360ce49 | ||
|
|
757cec9ddd | ||
|
|
53d0e6dd6a | ||
|
|
f4ac41806a | ||
|
|
f0fc95a143 | ||
|
|
83e047eaa7 | ||
|
|
f718aedd9f | ||
|
|
096e06dbb5 | ||
|
|
c26f3a9bd1 | ||
|
|
f1e7570755 | ||
|
|
8ece75aee1 | ||
|
|
985302c7cc | ||
|
|
7563424f32 | ||
|
|
ae2fe472c3 | ||
|
|
0ec6e88048 | ||
|
|
1d764d631f | ||
|
|
8c35bfbadf | ||
|
|
1844b2fdb4 | ||
|
|
0c7fd94585 | ||
|
|
5f9861953e | ||
|
|
cf2f7c30a3 | ||
|
|
d17ac27a72 | ||
|
|
b56843b253 | ||
|
|
e54f330239 | ||
|
|
8b4d653663 | ||
|
|
928d3a011c | ||
|
|
768e5d52fb | ||
|
|
49232d1abf | ||
|
|
5026891d75 | ||
|
|
adc704563c | ||
|
|
d44ac73925 | ||
|
|
746ea6bd86 | ||
|
|
462f5d98a2 | ||
|
|
cd8c905dfe | ||
|
|
a7d45c5a7a | ||
|
|
385f730f31 | ||
|
|
790fe2e558 | ||
|
|
34aa3112c8 | ||
|
|
2643ce97ae | ||
|
|
20f19893cb | ||
|
|
8892579f8b | ||
|
|
5849bd472a | ||
|
|
62e0453ce0 | ||
|
|
bb361cc644 | ||
|
|
7dc04f4091 | ||
|
|
29b79e4c0e | ||
|
|
a6f18e4686 | ||
|
|
5a060b8dc8 | ||
|
|
91dace35a1 | ||
|
|
55bb0cfbb6 | ||
|
|
0f1707de67 | ||
|
|
966ae00fe4 | ||
|
|
0071a540d4 | ||
|
|
0fb78eae34 | ||
|
|
fe78c9ae8b | ||
|
|
ca81464697 | ||
|
|
09b4e26a44 | ||
|
|
524843af01 | ||
|
|
4843b55fd1 | ||
|
|
a3957d089a | ||
|
|
5b36c0336f | ||
|
|
28d257da11 | ||
|
|
51ce20d5da | ||
|
|
9f5b11e6fd | ||
|
|
5e794a9ab7 | ||
|
|
1653f97c8f | ||
|
|
8f737d28a6 | ||
|
|
9fc0a15cd4 | ||
|
|
0985816bf6 | ||
|
|
af4006b3f5 | ||
|
|
b07ea7c74b | ||
|
|
ac7c7ab99a | ||
|
|
67d4cbab46 | ||
|
|
82f66082b9 | ||
|
|
3986a05c62 | ||
|
|
6da3b29e37 | ||
|
|
99fdc1d829 | ||
|
|
df1a110d2e | ||
|
|
80af836ce0 | ||
|
|
6f7d45a323 | ||
|
|
22db3f2c77 | ||
|
|
5a3cb32e59 | ||
|
|
ea933b03b4 | ||
|
|
139d2f7c29 | ||
|
|
89b5616d10 | ||
|
|
45dcf63a62 | ||
|
|
a6cd0b08f6 | ||
|
|
85a2229264 | ||
|
|
5e19030aa1 | ||
|
|
4dca553e66 | ||
|
|
ae744c8b78 | ||
|
|
c6aa86afc2 | ||
|
|
839c4e7966 | ||
|
|
d960a335f8 | ||
|
|
3ef1f41550 | ||
|
|
97ec4e50b1 | ||
|
|
591b5c0f41 | ||
|
|
55f19cb809 | ||
|
|
a24ea3dab7 | ||
|
|
bc05562730 | ||
|
|
4830ff923e | ||
|
|
ffd8060a98 | ||
|
|
661834d02b | ||
|
|
9dfa3c3e04 | ||
|
|
46667ba3e4 | ||
|
|
8bb9660baa | ||
|
|
a3878873f3 | ||
|
|
c05271901a | ||
|
|
d2f7778cc7 | ||
|
|
875f71d4ef | ||
|
|
b34c5f3c0f | ||
|
|
7f3ccb59da | ||
|
|
eb793429f1 | ||
|
|
5456ef3092 | ||
|
|
c59abe2589 | ||
|
|
271f9faf9e | ||
|
|
0c587936c7 | ||
|
|
2692ed3f01 | ||
|
|
23f59e7023 | ||
|
|
37244c2f7f | ||
|
|
8f10a28890 | ||
|
|
7fa4443f77 | ||
|
|
457754d2c2 | ||
|
|
c5b3ffd8d5 | ||
|
|
623b987813 | ||
|
|
090e5b40f1 | ||
|
|
d32148567f | ||
|
|
23aa78c405 | ||
|
|
97521b5257 | ||
|
|
66331f2b51 | ||
|
|
1f5a7cef6f | ||
|
|
a8fef7f569 | ||
|
|
5e7c4f3be8 | ||
|
|
58b01afc50 | ||
|
|
508471bbc0 | ||
|
|
4d3dda5d9f | ||
|
|
b66737e6df | ||
|
|
b8a5e30d91 | ||
|
|
f93727aa56 | ||
|
|
c485a0636e | ||
|
|
e0feedd7ac | ||
|
|
33a53bc13b | ||
|
|
133dce6a37 | ||
|
|
81c45c0a94 | ||
|
|
840470ec79 | ||
|
|
5d21ffe16b | ||
|
|
037a8daee6 | ||
|
|
a2de039ec4 | ||
|
|
5d53f48acb | ||
|
|
e6fd96f054 | ||
|
|
5146599b01 | ||
|
|
b354251f1a | ||
|
|
9245ff5705 | ||
|
|
1eb2d8e0bf | ||
|
|
0981b80c29 | ||
|
|
bfbfb53ed4 | ||
|
|
b84172434d | ||
|
|
9d9aae0396 | ||
|
|
11b729d8a2 | ||
|
|
d54e6e8359 | ||
|
|
2abbe5fc88 | ||
|
|
1ad3b7d5c0 | ||
|
|
d285c7bf2c | ||
|
|
2e767410b8 | ||
|
|
c164396ddc | ||
|
|
92dca80975 | ||
|
|
11353b0c57 | ||
|
|
3e468840bd | ||
|
|
e17018adcd | ||
|
|
3b6ed2294b | ||
|
|
50a3855082 | ||
|
|
9e11cb53dd | ||
|
|
5ac114c756 | ||
|
|
6ddf861078 | ||
|
|
6bdb06a7b1 | ||
|
|
2ea78ec7fd | ||
|
|
09570add5f | ||
|
|
f621326c24 | ||
|
|
781fc2c8c0 | ||
|
|
1302257e5d | ||
|
|
96c5269511 | ||
|
|
e9205293bd | ||
|
|
203f9e6c00 | ||
|
|
82ab06b849 | ||
|
|
ab89d75daf | ||
|
|
2387a7a969 | ||
|
|
7e63dc3615 | ||
|
|
74335bd32a | ||
|
|
d4e09300f3 | ||
|
|
a2ea797593 | ||
|
|
2f1dca645b | ||
|
|
f1ae31d8af | ||
|
|
fa8cc47c4f | ||
|
|
a5f95d75a1 | ||
|
|
1f7e0e51aa | ||
|
|
1ef3a48c03 | ||
|
|
356c3cad1a | ||
|
|
28bddf4590 | ||
|
|
3d0a83aeb2 | ||
|
|
f49d4f0e93 | ||
|
|
7d5bb42946 | ||
|
|
46692fc929 | ||
|
|
6860133373 | ||
|
|
52d4975825 | ||
|
|
4295311da3 | ||
|
|
0e69fc6e84 | ||
|
|
46f552a9fe | ||
|
|
4fdc8a62d0 | ||
|
|
5b8def797c | ||
|
|
bd1aabe941 | ||
|
|
56f1e91239 | ||
|
|
29a86a1735 | ||
|
|
82e6b92b0a | ||
|
|
46c08874aa | ||
|
|
7b74bd4928 | ||
|
|
dd62ca1b29 | ||
|
|
d7d7d81a6a | ||
|
|
6ad47ddf40 | ||
|
|
092522af6c | ||
|
|
bdef43dde7 | ||
|
|
e400258bf0 | ||
|
|
460c51fdad | ||
|
|
3793fa09ff | ||
|
|
c8a3917089 | ||
|
|
4c9183e8bb | ||
|
|
6672400206 | ||
|
|
1f6f261ace | ||
|
|
393a0edc51 | ||
|
|
3118d11d88 | ||
|
|
d0ccf0c755 | ||
|
|
397737b913 | ||
|
|
19b6958cfd | ||
|
|
39857190de | ||
|
|
478b01d9a7 | ||
|
|
9bab521df8 | ||
|
|
a012e2db59 | ||
|
|
933f2715d8 | ||
|
|
60a87bce87 | ||
|
|
dab7acdf45 | ||
|
|
86c47a5636 | ||
|
|
1210aa435f | ||
|
|
e23a121afe | ||
|
|
65c2ad687f | ||
|
|
234db30d66 | ||
|
|
e099e1568a | ||
|
|
ca97bde8ff | ||
|
|
024fa1cb44 | ||
|
|
061a001590 | ||
|
|
10ab9c2f42 | ||
|
|
24de922636 | ||
|
|
8a6329a7ac | ||
|
|
50d710496d | ||
|
|
e19ccfa657 | ||
|
|
6d25b0e99a | ||
|
|
3ee5f8aac3 | ||
|
|
68103043ce | ||
|
|
aab1f950aa | ||
|
|
bd51e8ef8a | ||
|
|
1c94f88d5e | ||
|
|
f8e4d43be7 | ||
|
|
00d971e1e7 | ||
|
|
810b4fad7d | ||
|
|
be8651dde7 | ||
|
|
ec4997d48f | ||
|
|
0acb1e715c | ||
|
|
6974aff668 | ||
|
|
0acbe31cfc | ||
|
|
cedcec2dec | ||
|
|
2b4d7735b6 | ||
|
|
2c31cfc271 | ||
|
|
dfead66eac | ||
|
|
27d4b53a5c | ||
|
|
b2997dc043 | ||
|
|
287ce61dc2 | ||
|
|
42ce57687a | ||
|
|
fdb204abb1 | ||
|
|
9e71a5cd23 | ||
|
|
08e663d7e2 | ||
|
|
e1ea3ce7aa | ||
|
|
cfc45319fe | ||
|
|
83743ed681 | ||
|
|
5e9dc15360 | ||
|
|
c2e8c8acd8 | ||
|
|
735a60698c | ||
|
|
5aa0b23825 | ||
|
|
1d8c7a9557 | ||
|
|
c0a0a93d02 | ||
|
|
7bd9c3a3cf | ||
|
|
ef758662c5 | ||
|
|
faf705a42a | ||
|
|
a2d0fcbe38 | ||
|
|
f4203de302 | ||
|
|
1d740055da | ||
|
|
457661f640 | ||
|
|
7dbe393629 | ||
|
|
d5eb41fa08 | ||
|
|
febe76e316 | ||
|
|
8449a8788a | ||
|
|
6a7a42be16 | ||
|
|
88dc2d6c6a | ||
|
|
b6c837cbe1 | ||
|
|
cdcc319c2d | ||
|
|
7be8b2ff9c | ||
|
|
e46704dd90 | ||
|
|
9862229d4d | ||
|
|
dc42bf52c1 | ||
|
|
00b9c0f4b2 | ||
|
|
9553c35d89 | ||
|
|
3b9e6b7820 | ||
|
|
c73ba23eb5 | ||
|
|
871c3557bf | ||
|
|
8c8e8c2e93 | ||
|
|
a6fa147c8d | ||
|
|
ac4161e25d | ||
|
|
559fc3c610 | ||
|
|
031eae7864 | ||
|
|
0a83c0fcef | ||
|
|
c23617fef3 | ||
|
|
caeddc5d37 | ||
|
|
1ffeb89a52 | ||
|
|
6b6aaa1698 | ||
|
|
ccd65d4261 | ||
|
|
9eace6b113 | ||
|
|
ed6d0b5f85 | ||
|
|
b97d54355e | ||
|
|
e873dc654c | ||
|
|
c581cc16bb | ||
|
|
ce8c93498a | ||
|
|
8bff8ac079 | ||
|
|
7fa3ad83a9 | ||
|
|
4941aad657 | ||
|
|
8f2b50f178 | ||
|
|
dd21ce5f1b | ||
|
|
ea9627979e | ||
|
|
865a0c1674 | ||
|
|
7a5452ffb3 | ||
|
|
088a13331b | ||
|
|
9fb89c26f3 | ||
|
|
0dd710acb6 | ||
|
|
c3fad8350b | ||
|
|
3a78f82a78 | ||
|
|
c376ac359e | ||
|
|
ab9dc75a18 | ||
|
|
ca4c4c53a8 | ||
|
|
d01903e751 | ||
|
|
8e45ed66dd | ||
|
|
235507ae48 | ||
|
|
5a701eb7ea | ||
|
|
fced2231f8 | ||
|
|
9ea8e60a0c | ||
|
|
c99ddfaa22 | ||
|
|
da7bbd9dfd | ||
|
|
6642ffb761 | ||
|
|
2e120f28e0 | ||
|
|
11cd416525 | ||
|
|
76d8170ce8 | ||
|
|
87207a2e08 | ||
|
|
8add7822ce | ||
|
|
1f29d399f4 | ||
|
|
f9f625fb32 | ||
|
|
2eb665c634 | ||
|
|
a7a0c7a1bf | ||
|
|
6f6f524f1a | ||
|
|
22014c31e5 | ||
|
|
46ba858817 | ||
|
|
3fddc8effc | ||
|
|
c1d0547cf6 | ||
|
|
b970067298 | ||
|
|
8deb9822e4 | ||
|
|
9925d34a49 | ||
|
|
2d67195ed2 | ||
|
|
e72c6a1830 | ||
|
|
6b8e7eefcc | ||
|
|
c3c203ccd9 | ||
|
|
7a743148c9 | ||
|
|
8b09cd3a4d | ||
|
|
b3a6e613fc | ||
|
|
b7dc02381f | ||
|
|
181400c3d5 | ||
|
|
d844cb58a8 | ||
|
|
7261945eb5 | ||
|
|
b1a99c3a1f | ||
|
|
1e8c62b29c | ||
|
|
9e0dba8c17 | ||
|
|
460b66b14b | ||
|
|
b87c0fc440 | ||
|
|
93e447b631 | ||
|
|
940e22fd81 | ||
|
|
4ac24cf59e | ||
|
|
ca2c1cb446 | ||
|
|
ee12c3d60c | ||
|
|
bcaa5f1c04 | ||
|
|
2232717cba | ||
|
|
5ca4f13b87 | ||
|
|
37e7e72041 | ||
|
|
4577167170 | ||
|
|
5d464a4a55 | ||
|
|
702764f53b | ||
|
|
b56772e5df | ||
|
|
a20c0d0f67 | ||
|
|
86d5634941 | ||
|
|
962e2fcdb6 | ||
|
|
1a275bac2b | ||
|
|
9c2c932f8c | ||
|
|
1044391135 | ||
|
|
f342dac1cb | ||
|
|
908037fe16 | ||
|
|
f8dcd5ca6f | ||
|
|
138d08c531 | ||
|
|
fa2544e79f | ||
|
|
3e34352222 | ||
|
|
42c63d3ad2 | ||
|
|
36949554ab | ||
|
|
93fb7489a7 | ||
|
|
9c24588e73 | ||
|
|
9362da78b0 | ||
|
|
9682087b65 | ||
|
|
f9781fc62e | ||
|
|
3acee27b14 | ||
|
|
7993454a92 | ||
|
|
0167938c26 | ||
|
|
e88ed65a39 | ||
|
|
399ff1fe05 | ||
|
|
895c12943b | ||
|
|
ea2cc8fc4a | ||
|
|
c7fa55bb87 | ||
|
|
78494ffecc | ||
|
|
4a8d0f3b10 | ||
|
|
7f10522c43 | ||
|
|
60d5ab3a16 | ||
|
|
5ce4c2a23a | ||
|
|
723cafcbcf | ||
|
|
e5c027b49b | ||
|
|
cf8525a571 | ||
|
|
fc42e9fae2 | ||
|
|
ea8c55cfd7 | ||
|
|
f487746ded | ||
|
|
3a8ca61bd0 | ||
|
|
092631f0ba | ||
|
|
712fd182b7 | ||
|
|
b0a7e05a45 | ||
|
|
cadae3588c | ||
|
|
5cccb13dad | ||
|
|
5a60b66a9d | ||
|
|
7cfbe1fee4 | ||
|
|
1a3f0da922 | ||
|
|
5d7cebdadc | ||
|
|
6cb6d62347 | ||
|
|
f0b5e9e116 | ||
|
|
98e6175874 | ||
|
|
75b6323200 | ||
|
|
7e7bcce2d9 | ||
|
|
55f69a4700 | ||
|
|
fc8c44e3d5 | ||
|
|
52d3a48128 | ||
|
|
703d64469e | ||
|
|
853a4a81b3 | ||
|
|
ec9a4904f3 | ||
|
|
3263a245bb | ||
|
|
a7a69cd07a | ||
|
|
e9de46c436 | ||
|
|
c7c0c93172 | ||
|
|
5519660a0d | ||
|
|
068ed1e838 | ||
|
|
9ceae8acea | ||
|
|
2675fe6218 | ||
|
|
85ea8b4f43 | ||
|
|
91c5132ab5 | ||
|
|
d3f220b2c2 | ||
|
|
fdef04e77b | ||
|
|
542a1380aa | ||
|
|
811bde8267 | ||
|
|
f3da2a88c9 | ||
|
|
b5271c8861 | ||
|
|
94e6967e98 | ||
|
|
7e05b97229 | ||
|
|
a1c3d8f14d | ||
|
|
f146061d24 | ||
|
|
dac1888c18 | ||
|
|
25c5eca893 | ||
|
|
f3f9da868e | ||
|
|
6293a9f87f | ||
|
|
83e914c1d5 | ||
|
|
94b5960ef3 | ||
|
|
9f18347034 | ||
|
|
3d1d5fafc1 | ||
|
|
0b637e0b86 | ||
|
|
7b2eecd428 | ||
|
|
8d29329f93 | ||
|
|
0ccb2c4f66 | ||
|
|
84560c41c7 | ||
|
|
dd675e01c4 | ||
|
|
be4502968e | ||
|
|
c698633447 | ||
|
|
c289d95d6b | ||
|
|
57de7cd603 | ||
|
|
bf5b80a8ae | ||
|
|
53cb1a49e7 | ||
|
|
a56881b005 | ||
|
|
e9f9282bde | ||
|
|
7b90edb5a6 | ||
|
|
6b8de05d0a | ||
|
|
4004b9a40b | ||
|
|
01a196e08d | ||
|
|
59e659fcc0 | ||
|
|
6eb339fae4 | ||
|
|
b3dbab33ca | ||
|
|
0ec76d834e | ||
|
|
bf1afb02ca | ||
|
|
a6aee96c7e | ||
|
|
a41957b873 | ||
|
|
439e1497e1 | ||
|
|
4a17e3e6b9 | ||
|
|
49e1501b5d | ||
|
|
958fe01c32 | ||
|
|
e12d131734 | ||
|
|
a6b4a11385 | ||
|
|
0e894be626 | ||
|
|
e53f03172a | ||
|
|
5cd806a03e | ||
|
|
ef12c2184d | ||
|
|
4538e45c46 | ||
|
|
100da73677 | ||
|
|
8f188ece3c | ||
|
|
4a43dfbf3e | ||
|
|
2e2c04e250 | ||
|
|
b2fe3a5ca6 | ||
|
|
3979a2ee6c | ||
|
|
2fac1028a8 | ||
|
|
c2b1ab072c | ||
|
|
a1a0469f91 | ||
|
|
6565f4e855 | ||
|
|
246c20e8a9 | ||
|
|
4046bdf18a | ||
|
|
0aa89c08ff | ||
|
|
89516bd4e0 | ||
|
|
7868808b2f | ||
|
|
ef14236539 | ||
|
|
eae82d8ee5 | ||
|
|
3f1bb1ac78 | ||
|
|
9aa459b294 | ||
|
|
d6b08f6f2c | ||
|
|
603061a7e5 | ||
|
|
4ac3eea027 | ||
|
|
8afd4699e6 | ||
|
|
7c4fabde60 | ||
|
|
bd9c6f88be | ||
|
|
ecf07f2729 | ||
|
|
0b99d1b574 | ||
|
|
aa3d4c0221 | ||
|
|
bb13d056ea | ||
|
|
840f69c582 | ||
|
|
652856fb63 | ||
|
|
44b69cf25e | ||
|
|
fa689db37b | ||
|
|
8864019f6d | ||
|
|
98ff031eb8 | ||
|
|
6c757e99f3 | ||
|
|
8e910c89b8 | ||
|
|
08ed96d856 | ||
|
|
f94177367a | ||
|
|
30dfc64f48 | ||
|
|
3cc0624932 | ||
|
|
21e875c958 | ||
|
|
5fee401fe1 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
src/version.cpp export-subst
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
src/*.exe
|
||||
src/bitcoin
|
||||
src/bitcoind
|
||||
src/test_bitcoin
|
||||
.*.swp
|
||||
*.*~*
|
||||
*.bak
|
||||
@@ -19,3 +20,4 @@ qrc_*.cpp
|
||||
*.pro.user
|
||||
#mac specific
|
||||
.DS_Store
|
||||
build
|
||||
|
||||
4
INSTALL
4
INSTALL
@@ -1,9 +1,9 @@
|
||||
Building Bitcoin
|
||||
|
||||
See doc/readme-qt.rst for instructions on building Bitcoin QT,
|
||||
See doc/readme-qt.rst for instructions on building Bitcoin-Qt,
|
||||
the intended-for-end-users, nice-graphical-interface, reference
|
||||
implementation of Bitcoin.
|
||||
|
||||
See doc/build-*.txt for instructions on building bitcoind,
|
||||
the intended-for-services, no-graphical-interface, reference
|
||||
implementation of Bitcoin.
|
||||
implementation of Bitcoin.
|
||||
145
bitcoin-qt.pro
145
bitcoin-qt.pro
@@ -1,19 +1,20 @@
|
||||
TEMPLATE = app
|
||||
TARGET =
|
||||
VERSION = 0.6.0
|
||||
TARGET = bitcoin-qt
|
||||
VERSION = 0.7.1
|
||||
INCLUDEPATH += src src/json src/qt
|
||||
DEFINES += QT_GUI BOOST_THREAD_USE_LIB
|
||||
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
|
||||
CONFIG += no_include_pwd
|
||||
CONFIG += thread
|
||||
|
||||
# for boost 1.37, add -mt to the boost libraries
|
||||
# for boost 1.37, add -mt to the boost libraries
|
||||
# use: qmake BOOST_LIB_SUFFIX=-mt
|
||||
# for boost thread win32 with _win32 sufix
|
||||
# use: BOOST_THREAD_LIB_SUFFIX=_win32-...
|
||||
# or when linking against a specific BerkelyDB version: BDB_LIB_SUFFIX=-4.8
|
||||
|
||||
# Dependency library locations can be customized with BOOST_INCLUDE_PATH,
|
||||
# BOOST_LIB_PATH, BDB_INCLUDE_PATH, BDB_LIB_PATH
|
||||
# OPENSSL_INCLUDE_PATH and OPENSSL_LIB_PATH respectively
|
||||
# Dependency library locations can be customized with:
|
||||
# BOOST_INCLUDE_PATH, BOOST_LIB_PATH, BDB_INCLUDE_PATH,
|
||||
# BDB_LIB_PATH, OPENSSL_INCLUDE_PATH and OPENSSL_LIB_PATH respectively
|
||||
|
||||
OBJECTS_DIR = build
|
||||
MOC_DIR = build
|
||||
@@ -30,6 +31,16 @@ contains(RELEASE, 1) {
|
||||
}
|
||||
}
|
||||
|
||||
!win32 {
|
||||
# for extra security against potential buffer overflows: enable GCCs Stack Smashing Protection
|
||||
QMAKE_CXXFLAGS *= -fstack-protector-all --param ssp-buffer-size=1
|
||||
QMAKE_LFLAGS *= -fstack-protector-all --param ssp-buffer-size=1
|
||||
# We need to exclude this for Windows cross compile with MinGW 4.2.x, as it will result in a non-working executable!
|
||||
# This can be enabled for Windows, when we switch to MinGW >= 4.4.x.
|
||||
}
|
||||
# for extra security on Windows: enable ASLR and DEP via GCC linker flags
|
||||
win32:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat
|
||||
|
||||
# use: qmake "USE_QRCODE=1"
|
||||
# libqrencode (http://fukuchi.org/works/qrencode/index.en.html) must be installed for support
|
||||
contains(USE_QRCODE, 1) {
|
||||
@@ -62,16 +73,16 @@ contains(USE_DBUS, 1) {
|
||||
QT += dbus
|
||||
}
|
||||
|
||||
# use: qmake "USE_SSL=1"
|
||||
contains(USE_SSL, 1) {
|
||||
message(Building with SSL support for RPC)
|
||||
DEFINES += USE_SSL
|
||||
}
|
||||
|
||||
# use: qmake "FIRST_CLASS_MESSAGING=1"
|
||||
contains(FIRST_CLASS_MESSAGING, 1) {
|
||||
message(Building with first-class messaging)
|
||||
DEFINES += FIRST_CLASS_MESSAGING
|
||||
# use: qmake "USE_IPV6=1" ( enabled by default; default)
|
||||
# or: qmake "USE_IPV6=0" (disabled by default)
|
||||
# or: qmake "USE_IPV6=-" (not supported)
|
||||
contains(USE_IPV6, -) {
|
||||
message(Building without IPv6 support)
|
||||
} else {
|
||||
count(USE_IPV6, 0) {
|
||||
USE_IPV6=1
|
||||
}
|
||||
DEFINES += USE_IPV6=$$USE_IPV6
|
||||
}
|
||||
|
||||
contains(BITCOIN_NEED_QT_PLUGINS, 1) {
|
||||
@@ -79,32 +90,38 @@ contains(BITCOIN_NEED_QT_PLUGINS, 1) {
|
||||
QTPLUGIN += qcncodecs qjpcodecs qtwcodecs qkrcodecs qtaccessiblewidgets
|
||||
}
|
||||
|
||||
!windows {
|
||||
# for extra security against potential buffer overflows
|
||||
QMAKE_CXXFLAGS += -fstack-protector
|
||||
QMAKE_LFLAGS += -fstack-protector
|
||||
# do not enable this on windows, as it will result in a non-working executable!
|
||||
|
||||
# regenerate src/build.h
|
||||
!windows|contains(USE_BUILD_INFO, 1) {
|
||||
genbuild.depends = FORCE
|
||||
genbuild.commands = cd $$PWD; /bin/sh share/genbuild.sh $$OUT_PWD/build/build.h
|
||||
genbuild.target = $$OUT_PWD/build/build.h
|
||||
PRE_TARGETDEPS += $$OUT_PWD/build/build.h
|
||||
QMAKE_EXTRA_TARGETS += genbuild
|
||||
DEFINES += HAVE_BUILD_INFO
|
||||
}
|
||||
|
||||
# disable quite some warnings because bitcoin core "sins" a lot
|
||||
QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wno-strict-aliasing -Wno-invalid-offsetof -Wno-unused-variable -Wno-unused-parameter -Wno-sign-compare -Wno-char-subscripts -Wno-unused-value -Wno-sequence-point -Wno-parentheses -Wno-unknown-pragmas -Wno-switch
|
||||
QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector
|
||||
|
||||
# Input
|
||||
DEPENDPATH += src/qt src src json/include
|
||||
DEPENDPATH += src src/json src/qt
|
||||
HEADERS += src/qt/bitcoingui.h \
|
||||
src/qt/transactiontablemodel.h \
|
||||
src/qt/addresstablemodel.h \
|
||||
src/qt/optionsdialog.h \
|
||||
src/qt/sendcoinsdialog.h \
|
||||
src/qt/addressbookpage.h \
|
||||
src/qt/messagepage.h \
|
||||
src/qt/signverifymessagedialog.h \
|
||||
src/qt/aboutdialog.h \
|
||||
src/qt/editaddressdialog.h \
|
||||
src/qt/bitcoinaddressvalidator.h \
|
||||
src/alert.h \
|
||||
src/addrman.h \
|
||||
src/base58.h \
|
||||
src/bignum.h \
|
||||
src/checkpoints.h \
|
||||
src/compat.h \
|
||||
src/sync.h \
|
||||
src/util.h \
|
||||
src/uint256.h \
|
||||
src/serialize.h \
|
||||
@@ -113,10 +130,9 @@ HEADERS += src/qt/bitcoingui.h \
|
||||
src/net.h \
|
||||
src/key.h \
|
||||
src/db.h \
|
||||
src/walletdb.h \
|
||||
src/script.h \
|
||||
src/noui.h \
|
||||
src/init.h \
|
||||
src/headers.h \
|
||||
src/irc.h \
|
||||
src/mruset.h \
|
||||
src/json/json_spirit_writer_template.h \
|
||||
@@ -134,7 +150,6 @@ HEADERS += src/qt/bitcoingui.h \
|
||||
src/qt/guiconstants.h \
|
||||
src/qt/optionsmodel.h \
|
||||
src/qt/monitoreddatamapper.h \
|
||||
src/qtui.h \
|
||||
src/qt/transactiondesc.h \
|
||||
src/qt/transactiondescdialog.h \
|
||||
src/qt/bitcoinamountfield.h \
|
||||
@@ -154,7 +169,13 @@ HEADERS += src/qt/bitcoingui.h \
|
||||
src/qt/askpassphrasedialog.h \
|
||||
src/protocol.h \
|
||||
src/qt/notificator.h \
|
||||
src/qt/qtipcserver.h
|
||||
src/qt/qtipcserver.h \
|
||||
src/allocators.h \
|
||||
src/ui_interface.h \
|
||||
src/qt/rpcconsole.h \
|
||||
src/version.h \
|
||||
src/netbase.h \
|
||||
src/clientversion.h
|
||||
|
||||
SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
||||
src/qt/transactiontablemodel.cpp \
|
||||
@@ -162,10 +183,13 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
||||
src/qt/optionsdialog.cpp \
|
||||
src/qt/sendcoinsdialog.cpp \
|
||||
src/qt/addressbookpage.cpp \
|
||||
src/qt/messagepage.cpp \
|
||||
src/qt/signverifymessagedialog.cpp \
|
||||
src/qt/aboutdialog.cpp \
|
||||
src/qt/editaddressdialog.cpp \
|
||||
src/qt/bitcoinaddressvalidator.cpp \
|
||||
src/alert.cpp \
|
||||
src/version.cpp \
|
||||
src/sync.cpp \
|
||||
src/util.cpp \
|
||||
src/netbase.cpp \
|
||||
src/key.cpp \
|
||||
@@ -175,10 +199,9 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
||||
src/net.cpp \
|
||||
src/irc.cpp \
|
||||
src/checkpoints.cpp \
|
||||
src/addrman.cpp \
|
||||
src/db.cpp \
|
||||
src/json/json_spirit_writer.cpp \
|
||||
src/json/json_spirit_value.cpp \
|
||||
src/json/json_spirit_reader.cpp \
|
||||
src/walletdb.cpp \
|
||||
src/qt/clientmodel.cpp \
|
||||
src/qt/guiutil.cpp \
|
||||
src/qt/transactionrecord.cpp \
|
||||
@@ -195,6 +218,11 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
||||
src/qt/walletmodel.cpp \
|
||||
src/bitcoinrpc.cpp \
|
||||
src/rpcdump.cpp \
|
||||
src/rpcnet.cpp \
|
||||
src/rpcmining.cpp \
|
||||
src/rpcwallet.cpp \
|
||||
src/rpcblockchain.cpp \
|
||||
src/rpcrawtransaction.cpp \
|
||||
src/qt/overviewpage.cpp \
|
||||
src/qt/csvmodelwriter.cpp \
|
||||
src/crypter.cpp \
|
||||
@@ -205,7 +233,9 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
||||
src/qt/askpassphrasedialog.cpp \
|
||||
src/protocol.cpp \
|
||||
src/qt/notificator.cpp \
|
||||
src/qt/qtipcserver.cpp
|
||||
src/qt/qtipcserver.cpp \
|
||||
src/qt/rpcconsole.cpp \
|
||||
src/noui.cpp
|
||||
|
||||
RESOURCES += \
|
||||
src/qt/bitcoin.qrc
|
||||
@@ -213,13 +243,15 @@ RESOURCES += \
|
||||
FORMS += \
|
||||
src/qt/forms/sendcoinsdialog.ui \
|
||||
src/qt/forms/addressbookpage.ui \
|
||||
src/qt/forms/messagepage.ui \
|
||||
src/qt/forms/signverifymessagedialog.ui \
|
||||
src/qt/forms/aboutdialog.ui \
|
||||
src/qt/forms/editaddressdialog.ui \
|
||||
src/qt/forms/transactiondescdialog.ui \
|
||||
src/qt/forms/overviewpage.ui \
|
||||
src/qt/forms/sendcoinsentry.ui \
|
||||
src/qt/forms/askpassphrasedialog.ui
|
||||
src/qt/forms/askpassphrasedialog.ui \
|
||||
src/qt/forms/rpcconsole.ui \
|
||||
src/qt/forms/optionsdialog.ui
|
||||
|
||||
contains(USE_QRCODE, 1) {
|
||||
HEADERS += src/qt/qrcodedialog.h
|
||||
@@ -229,8 +261,8 @@ FORMS += src/qt/forms/qrcodedialog.ui
|
||||
|
||||
contains(BITCOIN_QT_TEST, 1) {
|
||||
SOURCES += src/qt/test/test_main.cpp \
|
||||
src/qt/test/urltests.cpp
|
||||
HEADERS += src/qt/test/urltests.h
|
||||
src/qt/test/uritests.cpp
|
||||
HEADERS += src/qt/test/uritests.h
|
||||
DEPENDPATH += src/qt/test
|
||||
QT += testlib
|
||||
TARGET = bitcoin-qt_test
|
||||
@@ -244,27 +276,26 @@ CODECFORTR = UTF-8
|
||||
TRANSLATIONS = $$files(src/qt/locale/bitcoin_*.ts)
|
||||
|
||||
isEmpty(QMAKE_LRELEASE) {
|
||||
win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe
|
||||
win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\\lrelease.exe
|
||||
else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
|
||||
}
|
||||
isEmpty(TS_DIR):TS_DIR = src/qt/locale
|
||||
isEmpty(QM_DIR):QM_DIR = $$PWD/src/qt/locale
|
||||
# automatically build translations, so they can be included in resource file
|
||||
TSQM.name = lrelease ${QMAKE_FILE_IN}
|
||||
TSQM.input = TRANSLATIONS
|
||||
TSQM.output = $$TS_DIR/${QMAKE_FILE_BASE}.qm
|
||||
TSQM.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN}
|
||||
TSQM.output = $$QM_DIR/${QMAKE_FILE_BASE}.qm
|
||||
TSQM.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_OUT}
|
||||
TSQM.CONFIG = no_link
|
||||
QMAKE_EXTRA_COMPILERS += TSQM
|
||||
PRE_TARGETDEPS += compiler_TSQM_make_all
|
||||
|
||||
# "Other files" to show in Qt Creator
|
||||
OTHER_FILES += \
|
||||
doc/*.rst doc/*.txt doc/README README.md
|
||||
doc/*.rst doc/*.txt doc/README README.md res/bitcoin-qt.rc src/test/*.cpp src/test/*.h src/qt/test/*.cpp src/qt/test/*.h
|
||||
|
||||
# platform specific defaults, if not overridden on command line
|
||||
isEmpty(BOOST_LIB_SUFFIX) {
|
||||
macx:BOOST_LIB_SUFFIX = -mt
|
||||
windows:BOOST_LIB_SUFFIX = -mgw44-mt-1_43
|
||||
windows:BOOST_LIB_SUFFIX = -mgw44-mt-s-1_50
|
||||
}
|
||||
|
||||
isEmpty(BOOST_THREAD_LIB_SUFFIX) {
|
||||
@@ -291,12 +322,24 @@ isEmpty(BOOST_INCLUDE_PATH) {
|
||||
macx:BOOST_INCLUDE_PATH = /opt/local/include
|
||||
}
|
||||
|
||||
windows:LIBS += -lws2_32 -lshlwapi
|
||||
windows:LIBS += -lws2_32 -lshlwapi -lmswsock
|
||||
windows:DEFINES += WIN32
|
||||
windows:RC_FILE = src/qt/res/bitcoin-qt.rc
|
||||
|
||||
!windows:!mac {
|
||||
windows:!contains(MINGW_THREAD_BUGFIX, 0) {
|
||||
# At least qmake's win32-g++-cross profile is missing the -lmingwthrd
|
||||
# thread-safety flag. GCC has -mthreads to enable this, but it doesn't
|
||||
# work with static linking. -lmingwthrd must come BEFORE -lmingw, so
|
||||
# it is prepended to QMAKE_LIBS_QT_ENTRY.
|
||||
# It can be turned off with MINGW_THREAD_BUGFIX=0, just in case it causes
|
||||
# any problems on some untested qmake profile now or in the future.
|
||||
DEFINES += _MT
|
||||
QMAKE_LIBS_QT_ENTRY = -lmingwthrd $$QMAKE_LIBS_QT_ENTRY
|
||||
}
|
||||
|
||||
!windows:!macx {
|
||||
DEFINES += LINUX
|
||||
LIBS += -lrt
|
||||
}
|
||||
|
||||
macx:HEADERS += src/qt/macdockiconhandler.h
|
||||
@@ -305,14 +348,18 @@ macx:LIBS += -framework Foundation -framework ApplicationServices -framework App
|
||||
macx:DEFINES += MAC_OSX MSG_NOSIGNAL=0
|
||||
macx:ICON = src/qt/res/icons/bitcoin.icns
|
||||
macx:TARGET = "Bitcoin-Qt"
|
||||
macx:QMAKE_CFLAGS_THREAD += -pthread
|
||||
macx:QMAKE_LFLAGS_THREAD += -pthread
|
||||
macx:QMAKE_CXXFLAGS_THREAD += -pthread
|
||||
|
||||
# Set libraries and includes at end, to use platform-defined defaults if not overridden
|
||||
INCLUDEPATH += $$BOOST_INCLUDE_PATH $$BDB_INCLUDE_PATH $$OPENSSL_INCLUDE_PATH $$QRENCODE_INCLUDE_PATH
|
||||
LIBS += $$join(BOOST_LIB_PATH,,-L,) $$join(BDB_LIB_PATH,,-L,) $$join(OPENSSL_LIB_PATH,,-L,) $$join(QRENCODE_LIB_PATH,,-L,)
|
||||
LIBS += -lssl -lcrypto -ldb_cxx$$BDB_LIB_SUFFIX
|
||||
# -lgdi32 has to happen after -lcrypto (see #681)
|
||||
windows:LIBS += -lgdi32
|
||||
windows:LIBS += -lole32 -luuid -lgdi32
|
||||
LIBS += -lboost_system$$BOOST_LIB_SUFFIX -lboost_filesystem$$BOOST_LIB_SUFFIX -lboost_program_options$$BOOST_LIB_SUFFIX -lboost_thread$$BOOST_THREAD_LIB_SUFFIX
|
||||
windows:LIBS += -lboost_chrono$$BOOST_LIB_SUFFIX
|
||||
|
||||
contains(RELEASE, 1) {
|
||||
!windows:!macx {
|
||||
|
||||
115
contrib/bitcoind.bash-completion
Normal file
115
contrib/bitcoind.bash-completion
Normal file
@@ -0,0 +1,115 @@
|
||||
# bash programmable completion for bitcoind(1)
|
||||
# Copyright (c) 2012 Christian von Roques <roques@mti.ag>
|
||||
# Distributed under the MIT/X11 software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
have bitcoind && {
|
||||
|
||||
# call $bitcoind for RPC
|
||||
_bitcoin_rpc() {
|
||||
# determine already specified args necessary for RPC
|
||||
local rpcargs=()
|
||||
for i in ${COMP_LINE}; do
|
||||
case "$i" in
|
||||
-conf=*|-proxy*|-rpc*)
|
||||
rpcargs=( "${rpcargs[@]}" "$i" )
|
||||
;;
|
||||
esac
|
||||
done
|
||||
$bitcoind "${rpcargs[@]}" "$@"
|
||||
}
|
||||
|
||||
# Add bitcoin accounts to COMPREPLY
|
||||
_bitcoin_accounts() {
|
||||
local accounts
|
||||
accounts=$(_bitcoin_rpc listaccounts | awk '/".*"/ { a=$1; gsub(/"/, "", a); print a}')
|
||||
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
|
||||
}
|
||||
|
||||
_bitcoind() {
|
||||
local cur prev words=() cword
|
||||
local bitcoind
|
||||
|
||||
# save and use original argument to invoke bitcoind
|
||||
# bitcoind might not be in $PATH
|
||||
bitcoind="$1"
|
||||
|
||||
COMPREPLY=()
|
||||
_get_comp_words_by_ref -n = cur prev words cword
|
||||
|
||||
if ((cword > 2)); then
|
||||
case ${words[cword-2]} in
|
||||
listreceivedbyaccount|listreceivedbyaddress)
|
||||
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
move|setaccount)
|
||||
_bitcoin_accounts
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
case "$prev" in
|
||||
backupwallet)
|
||||
_filedir
|
||||
return 0
|
||||
;;
|
||||
setgenerate)
|
||||
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
|
||||
_bitcoin_accounts
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-conf=*|-pid=*|-rpcsslcertificatechainfile=*|-rpcsslprivatekeyfile=*)
|
||||
cur="${cur#*=}"
|
||||
_filedir
|
||||
return 0
|
||||
;;
|
||||
-datadir=*)
|
||||
cur="${cur#*=}"
|
||||
_filedir -d
|
||||
return 0
|
||||
;;
|
||||
-*=*) # prevent nonsense completions
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
local helpopts commands
|
||||
|
||||
# only parse --help if senseful
|
||||
if [[ -z "$cur" || "$cur" =~ ^- ]]; then
|
||||
helpopts=$($bitcoind --help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
|
||||
fi
|
||||
|
||||
# only parse help if senseful
|
||||
if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
|
||||
commands=$(_bitcoin_rpc help 2>/dev/null | awk '{ print $1; }')
|
||||
fi
|
||||
|
||||
COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
|
||||
|
||||
# Prevent space if an argument is desired
|
||||
if [[ $COMPREPLY == *= ]]; then
|
||||
compopt -o nospace
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
complete -F _bitcoind bitcoind
|
||||
}
|
||||
|
||||
# Local variables:
|
||||
# mode: shell-script
|
||||
# sh-basic-offset: 4
|
||||
# sh-indent-comment: t
|
||||
# indent-tabs-mode: nil
|
||||
# End:
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
umask 077
|
||||
|
||||
basedir=~/.bitcoin
|
||||
dbfile="$basedir/DB_CONFIG"
|
||||
cfgfile="$basedir/bitcoin.conf"
|
||||
|
||||
[ -e "$basedir" ] || mkdir "$basedir"
|
||||
|
||||
# Bitcoin does not clean up DB log files by default
|
||||
[ -e "$dbfile" ] || echo 'set_flags DB_LOG_AUTOREMOVE' > "$dbfile"
|
||||
|
||||
exec /usr/lib/bitcoin/bitcoin-qt "$@"
|
||||
@@ -5,14 +5,10 @@ set -e
|
||||
umask 077
|
||||
|
||||
basedir=~/.bitcoin
|
||||
dbfile="$basedir/DB_CONFIG"
|
||||
cfgfile="$basedir/bitcoin.conf"
|
||||
|
||||
[ -e "$basedir" ] || mkdir "$basedir"
|
||||
|
||||
[ -e "$cfgfile" ] || perl -le 'print"rpcpassword=",map{(a..z,A..Z,0..9)[rand 62]}0..9' > "$cfgfile"
|
||||
|
||||
# Bitcoin does not clean up DB log files by default
|
||||
[ -e "$dbfile" ] || echo 'set_flags DB_LOG_AUTOREMOVE' > "$dbfile"
|
||||
|
||||
exec /usr/lib/bitcoin/bitcoind "$@"
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Encoding=UTF-8
|
||||
Name=Bitcoin
|
||||
Comment=Bitcoin P2P Cryptocurrency
|
||||
Comment[fr]=Bitcoin, monnaie virtuelle cryptographique pair à pair
|
||||
Comment[tr]=Bitcoin, eşten eşe kriptografik sanal para birimi
|
||||
Exec=/usr/bin/bitcoin-qt
|
||||
Terminal=false
|
||||
Type=Application
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
debian/bin/bitcoin-qt usr/bin
|
||||
bitcoin-qt usr/lib/bitcoin
|
||||
bitcoin-qt usr/bin
|
||||
share/pixmaps/bitcoin32.xpm usr/share/pixmaps
|
||||
share/pixmaps/bitcoin80.xpm usr/share/pixmaps
|
||||
debian/bitcoin-qt.desktop usr/share/applications
|
||||
|
||||
1
contrib/debian/bitcoind.bash-completion
Normal file
1
contrib/debian/bitcoind.bash-completion
Normal file
@@ -0,0 +1 @@
|
||||
contrib/bitcoind.bash-completion bitcoind
|
||||
@@ -1,13 +1,61 @@
|
||||
bitcoin (0.5.1-natty1) natty; urgency=low
|
||||
bitcoin (0.6.3-natty1) natty; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Matt Corallo <matt@bluematt.me> Mon, 25 Jun 2012 23:47:00 +0200
|
||||
|
||||
bitcoin (0.6.2-natty1) natty; urgency=low
|
||||
|
||||
* Update package description and launch scripts.
|
||||
|
||||
-- Matt Corallo <matt@bluematt.me> Sat, 2 Jun 2012 16:41:00 +0200
|
||||
|
||||
bitcoin (0.6.2-natty0) natty; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Matt Corallo <matt@bluematt.me> Tue, 8 May 2012 16:27:00 -0500
|
||||
|
||||
bitcoin (0.6.1-natty0) natty; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Matt Corallo <matt@bluematt.me> Sun, 6 May 2012 20:09:00 -0500
|
||||
|
||||
bitcoin (0.6.0-natty0) natty; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
* Add GNOME/KDE support for bitcoin-qt's bitcoin: URI support.
|
||||
Thanks to luke-jr for the KDE .protocol file.
|
||||
|
||||
-- Matt Corallo <matt@bluematt.me> Sat, 31 Mar 2012 15:35:00 -0500
|
||||
|
||||
bitcoin (0.5.3-natty1) natty; urgency=low
|
||||
|
||||
* Mark for upload to PPA.
|
||||
|
||||
-- Matt Corallo <matt@bluematt.me> Wed, 14 Mar 2012 23:06:00 -0400
|
||||
|
||||
bitcoin (0.5.3-natty0) natty; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Luke Dashjr <luke+bitcoin+deb@dashjr.org> Tue, 10 Jan 2012 15:57:00 -0500
|
||||
|
||||
bitcoin (0.5.2-natty1) natty; urgency=low
|
||||
|
||||
* Remove mentions on anonymity in package descriptions and manpage.
|
||||
These should never have been there, bitcoin isnt anonymous without
|
||||
a ton of work that virtually no users will ever be willing and
|
||||
capable of doing
|
||||
* Add GNOME/KDE support for bitcoin-qt's bitcoin: URI support.
|
||||
Thanks to luke-jr for the KDE .protocol file.
|
||||
|
||||
-- Matt Corallo <matt@bluematt.me> Fri, 23 Dec 2011 20:25:00 -0500
|
||||
-- Matt Corallo <matt@bluematt.me> Sat, 7 Jan 2012 13:37:00 -0500
|
||||
|
||||
bitcoin (0.5.2-natty0) natty; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Luke Dashjr <luke+bitcoin+deb@dashjr.org> Fri, 16 Dec 2011 17:57:00 -0500
|
||||
|
||||
bitcoin (0.5.1-natty0) natty; urgency=low
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ Maintainer: Jonas Smedegaard <dr@jones.dk>
|
||||
Uploaders: Micah Anderson <micah@debian.org>
|
||||
Build-Depends: debhelper,
|
||||
devscripts,
|
||||
bash-completion,
|
||||
libboost-system-dev (>> 1.35) | libboost-system1.35-dev,
|
||||
libdb4.8++-dev,
|
||||
libssl-dev,
|
||||
@@ -35,7 +36,7 @@ Description: peer-to-peer network based digital currency - daemon
|
||||
By default connects to an IRC network to discover other peers.
|
||||
.
|
||||
Full transaction history is stored locally at each client. This
|
||||
requires 150+ MB of space, slowly growing.
|
||||
requires 2+ GB of space, slowly growing.
|
||||
.
|
||||
This package provides bitcoind, a combined daemon and CLI tool to
|
||||
interact with the daemon.
|
||||
@@ -43,7 +44,7 @@ Description: peer-to-peer network based digital currency - daemon
|
||||
Package: bitcoin-qt
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: peer-to-peer network based digital currency - QT GUI
|
||||
Description: peer-to-peer network based digital currency - Qt GUI
|
||||
Bitcoin is a free open source peer-to-peer electronic cash system that
|
||||
is completely decentralized, without the need for a central server or
|
||||
trusted parties. Users hold the crypto keys to their own money and
|
||||
@@ -53,6 +54,6 @@ Description: peer-to-peer network based digital currency - QT GUI
|
||||
By default connects to an IRC network to discover other peers.
|
||||
.
|
||||
Full transaction history is stored locally at each client. This
|
||||
requires 150+ MB of space, slowly growing.
|
||||
requires 2+ GB of space, slowly growing.
|
||||
.
|
||||
This package provides bitcoin-qt, a GUI for Bitcoin based on QT.
|
||||
This package provides Bitcoin-Qt, a GUI for Bitcoin based on Qt.
|
||||
|
||||
@@ -6,7 +6,7 @@ Source: http://sourceforge.net/projects/bitcoin/files/
|
||||
https://github.com/bitcoin/bitcoin
|
||||
|
||||
Files: *
|
||||
Copyright: 2009-2011, Bitcoin Developers
|
||||
Copyright: 2009-2012, Bitcoin Developers
|
||||
License: Expat
|
||||
Comment: The Bitcoin Developers encompasses the current developers listed on bitcoin.org,
|
||||
as well as the numerous contributors to the project.
|
||||
@@ -55,9 +55,8 @@ Comment: Icon Pack: Human-O2
|
||||
|
||||
Files: src/qt/res/icons/transaction*.png
|
||||
Copyright: md2k7
|
||||
License: You are free to do with these icons as you wish, including selling,
|
||||
copying, modifying etc.
|
||||
Comment: Site: https://forum.bitcoin.org/index.php?topic=15276.0
|
||||
License: Expat
|
||||
Comment: Site: https://bitcointalk.org/index.php?topic=15276.0
|
||||
|
||||
Files: src/qt/res/icons/configure.png, src/qt/res/icons/quit.png,
|
||||
src/qt/res/icons/editcopy.png, src/qt/res/icons/editpaste.png,
|
||||
@@ -70,7 +69,7 @@ Comment: Icon Pack: Crystal SVG
|
||||
Files: src/qt/res/icons/bitcoin.png, src/qt/res/icons/toolbar.png
|
||||
Copyright: Bitboy (optimized for 16x16 by Wladimir van der Laan)
|
||||
License: PUB-DOM
|
||||
Comment: Site: http://forum.bitcoin.org/?topic=1756.0
|
||||
Comment: Site: https://bitcointalk.org/?topic=1756.0
|
||||
|
||||
Files: scripts/img/reload.xcf, src/qt/res/movies/update_spinner.mng
|
||||
Copyright: Everaldo (Everaldo Coelho)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
Description: Use system JSON Spirit library
|
||||
Author: Jonas Smedegaard <dr@jones.dk>
|
||||
Last-Update: 2011-05-17
|
||||
--- a/src/rpc.cpp
|
||||
+++ b/src/rpc.cpp
|
||||
@@ -12,9 +12,7 @@
|
||||
#include <boost/asio/ssl.hpp>
|
||||
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream;
|
||||
#endif
|
||||
-#include "json/json_spirit_reader_template.h"
|
||||
-#include "json/json_spirit_writer_template.h"
|
||||
-#include "json/json_spirit_utils.h"
|
||||
+#include <json_spirit.h>
|
||||
#define printf OutputDebugStringF
|
||||
// MinGW 3.4.5 gets "fatal error: had to relocate PCH" if the json headers are
|
||||
// precompiled in headers.h. The problem might be when the pch file goes over
|
||||
--- a/src/makefile.unix
|
||||
+++ b/src/makefile.unix
|
||||
@@ -23,6 +23,7 @@
|
||||
-l boost_thread \
|
||||
-l db_cxx \
|
||||
-l ssl \
|
||||
+ -l json_spirit \
|
||||
-l crypto
|
||||
|
||||
ifdef USE_UPNP
|
||||
@@ -1 +1 @@
|
||||
#1001_use_system_json-spirit.patch
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ DEB_INSTALL_EXAMPLES_bitcoind += debian/examples/*
|
||||
DEB_INSTALL_MANPAGES_bitcoind += debian/manpages/*
|
||||
|
||||
%:
|
||||
dh $@
|
||||
dh --with bash-completion $@
|
||||
|
||||
override_dh_auto_build:
|
||||
cd src; $(MAKE) -f makefile.unix bitcoind
|
||||
@@ -20,7 +20,7 @@ override_dh_auto_clean:
|
||||
cd src; $(MAKE) -f makefile.unix clean
|
||||
|
||||
override_dh_auto_configure:
|
||||
qmake bitcoin-qt.pro USE_SSL=1 USE_QRCODE=1
|
||||
qmake bitcoin-qt.pro USE_QRCODE=1
|
||||
|
||||
override_dh_auto_test:
|
||||
cd src; $(MAKE) -f makefile.unix test_bitcoin
|
||||
|
||||
@@ -1,31 +1,86 @@
|
||||
Gavin's notes on getting gitian builds up and running:
|
||||
Gavin's notes on getting gitian builds up and running using KVM:
|
||||
|
||||
These instructions distilled from:
|
||||
https://help.ubuntu.com/community/KVM/Installation
|
||||
... see there for complete details.
|
||||
|
||||
You need the right hardware: you need a 64-bit-capable CPU with hardware virtualization support (Intel VT-x or AMD-V). Not all modern CPUs support hardware virtualization.
|
||||
|
||||
You probably need to enable hardware virtualization in your machine's BIOS.
|
||||
|
||||
You need to be running a recent version of 64-bit-Ubuntu, and you need to install several prerequisites:
|
||||
sudo apt-get install apache2 git apt-cacher-ng python-vm-builder qemu-kvm
|
||||
sudo apt-get install ruby apache2 git apt-cacher-ng python-vm-builder qemu-kvm
|
||||
|
||||
Sanity checks:
|
||||
sudo service apt-cacher-ng status # Should return apt-cacher-ng is running
|
||||
ls -l /dev/kvm # Should show a /dev/kvm device
|
||||
|
||||
|
||||
Once you've got the right hardware and software:
|
||||
|
||||
git clone git://github.com/bitcoin/bitcoin.git
|
||||
git clone git://github.com/devrandom/gitian-builder.git
|
||||
mkdir gitian-builder/inputs
|
||||
wget 'http://miniupnp.tuxfamily.org/files/download.php?file=miniupnpc-1.6.tar.gz' -O gitian-builder/inputs/miniupnpc-1.6.tar.gz
|
||||
cd gitian-builder/inputs
|
||||
# Inputs for Linux and Win32:
|
||||
wget -O miniupnpc-1.6.tar.gz 'http://miniupnp.tuxfamily.org/files/download.php?file=miniupnpc-1.6.tar.gz'
|
||||
wget 'http://fukuchi.org/works/qrencode/qrencode-3.2.0.tar.bz2'
|
||||
# Inputs for Win32: (Linux has packages for these)
|
||||
wget 'https://downloads.sourceforge.net/project/boost/boost/1.50.0/boost_1_50_0.tar.bz2'
|
||||
wget 'http://www.openssl.org/source/openssl-1.0.1c.tar.gz'
|
||||
wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
|
||||
wget 'https://downloads.sourceforge.net/project/libpng/zlib/1.2.6/zlib-1.2.6.tar.gz'
|
||||
wget 'https://downloads.sourceforge.net/project/libpng/libpng15/older-releases/1.5.9/libpng-1.5.9.tar.gz'
|
||||
wget 'http://releases.qt-project.org/qt4/source/qt-everywhere-opensource-src-4.8.2.tar.gz'
|
||||
cd ../..
|
||||
|
||||
cd gitian-builder
|
||||
bin/make-base-vm --arch i386
|
||||
bin/make-base-vm --arch amd64
|
||||
cd ..
|
||||
|
||||
# To build
|
||||
# Build Linux release:
|
||||
cd bitcoin
|
||||
git pull
|
||||
cd ../gitian-builder
|
||||
git pull
|
||||
./bin/gbuild --commit bitcoin=HEAD ../bitcoin/contrib/gitian.yml
|
||||
./bin/gbuild --commit bitcoin=HEAD ../bitcoin/contrib/gitian-descriptors/gitian.yml
|
||||
|
||||
# Build Win32 dependencies: (only needs to be done once, or when dependency versions change)
|
||||
./bin/gbuild --commit bitcoin=HEAD ../bitcoin/contrib/gitian-descriptors/boost-win32.yml
|
||||
./bin/gbuild --commit bitcoin=HEAD ../bitcoin/contrib/gitian-descriptors/deps-win32.yml
|
||||
./bin/gbuild --commit bitcoin=HEAD ../bitcoin/contrib/gitian-descriptors/qt-win32.yml
|
||||
|
||||
# Build Win32 release:
|
||||
./bin/gbuild --commit bitcoin=HEAD ../bitcoin/contrib/gitian-descriptors/gitian-win32.yml
|
||||
|
||||
---------------------
|
||||
|
||||
gitian-builder now also supports building using LXC. See
|
||||
https://help.ubuntu.com/12.04/serverguide/lxc.html
|
||||
... for how to get LXC up and running under Ubuntu.
|
||||
|
||||
If your main machine is a 64-bit Mac or PC with a few gigabytes of memory
|
||||
and at least 10 gigabytes of free disk space, you can gitian-build using
|
||||
LXC running inside a virtual machine.
|
||||
|
||||
Here's a description of Gavin's setup on OSX 10.6:
|
||||
|
||||
1. Download and install VirtualBox from https://www.virtualbox.org/
|
||||
|
||||
2. Download the 64-bit Ubuntu Desktop 12.04 LTS .iso CD image from
|
||||
http://www.ubuntu.com/
|
||||
|
||||
3. Run VirtualBox and create a new virtual machine, using the
|
||||
Ubuntu .iso (see the VirtualBox documentation for details).
|
||||
Create it with at least 2 gigabytes of memory and a disk
|
||||
that is at least 20 gigabytes big.
|
||||
|
||||
4. Inside the running Ubuntu desktop, install:
|
||||
sudo apt-get install debootstrap lxc ruby apache2 git apt-cacher-ng python-vm-builder
|
||||
|
||||
5. Still inside Ubuntu, tell gitian-builder to use LXC, then follow the "Once you've got the right
|
||||
hardware and software" instructions above:
|
||||
export USE_LXC=1
|
||||
git clone git://github.com/bitcoin/bitcoin.git
|
||||
... etc
|
||||
|
||||
@@ -11,12 +11,12 @@ packages:
|
||||
reference_datetime: "2011-01-30 00:00:00"
|
||||
remotes: []
|
||||
files:
|
||||
- "boost_1_47_0.tar.bz2"
|
||||
- "boost_1_50_0.tar.bz2"
|
||||
script: |
|
||||
TMPDIR="$HOME/tmpdir"
|
||||
mkdir -p $TMPDIR/bin/$GBUILD_BITS $TMPDIR/include
|
||||
tar xjf boost_1_47_0.tar.bz2
|
||||
cd boost_1_47_0
|
||||
tar xjf boost_1_50_0.tar.bz2
|
||||
cd boost_1_50_0
|
||||
echo "using gcc : 4.4 : i586-mingw32msvc-g++
|
||||
:
|
||||
<rc>i586-mingw32msvc-windres
|
||||
@@ -34,5 +34,5 @@ script: |
|
||||
cd $TMPDIR
|
||||
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
|
||||
export FAKETIME=$REFERENCE_DATETIME
|
||||
zip -r boost-win32-1.47.0-gitian.zip *
|
||||
cp boost-win32-1.47.0-gitian.zip $OUTDIR
|
||||
zip -r boost-win32-1.50.0-gitian2.zip *
|
||||
cp boost-win32-1.50.0-gitian2.zip $OUTDIR
|
||||
|
||||
@@ -4,7 +4,7 @@ suites:
|
||||
- "lucid"
|
||||
architectures:
|
||||
- "i386"
|
||||
packages:
|
||||
packages:
|
||||
- "mingw32"
|
||||
- "git-core"
|
||||
- "zip"
|
||||
@@ -13,7 +13,7 @@ packages:
|
||||
reference_datetime: "2011-01-30 00:00:00"
|
||||
remotes: []
|
||||
files:
|
||||
- "openssl-1.0.0e.tar.gz"
|
||||
- "openssl-1.0.1c.tar.gz"
|
||||
- "db-4.8.30.NC.tar.gz"
|
||||
- "miniupnpc-1.6.tar.gz"
|
||||
- "zlib-1.2.6.tar.gz"
|
||||
@@ -25,8 +25,8 @@ script: |
|
||||
export FAKETIME=$REFERENCE_DATETIME
|
||||
export TZ=UTC
|
||||
#
|
||||
tar xzf openssl-1.0.0e.tar.gz
|
||||
cd openssl-1.0.0e
|
||||
tar xzf openssl-1.0.1c.tar.gz
|
||||
cd openssl-1.0.1c
|
||||
./Configure --cross-compile-prefix=i586-mingw32msvc- mingw
|
||||
make
|
||||
cd ..
|
||||
@@ -62,7 +62,7 @@ script: |
|
||||
make $MAKEOPTS
|
||||
cd ..
|
||||
#
|
||||
zip -r $OUTDIR/bitcoin-deps-0.0.3.zip \
|
||||
zip -r $OUTDIR/bitcoin-deps-0.0.5.zip \
|
||||
$(ls qrencode-*/{qrencode.h,.libs/libqrencode.{,l}a} | sort) \
|
||||
$(ls db-*/build_unix/{libdb_cxx.a,db.h,db_cxx.h,libdb.a,.libs/libdb_cxx-?.?.a} | sort) \
|
||||
$(find openssl-* -name '*.a' -o -name '*.h' | sort) \
|
||||
|
||||
@@ -4,7 +4,7 @@ suites:
|
||||
- "lucid"
|
||||
architectures:
|
||||
- "i386"
|
||||
packages:
|
||||
packages:
|
||||
- "mingw32"
|
||||
- "git-core"
|
||||
- "unzip"
|
||||
@@ -15,21 +15,21 @@ remotes:
|
||||
- "url": "https://github.com/bitcoin/bitcoin.git"
|
||||
"dir": "bitcoin"
|
||||
files:
|
||||
- "qt-win32-4.7.4-gitian.zip"
|
||||
- "boost-win32-1.47.0-gitian.zip"
|
||||
- "bitcoin-deps-0.0.3.zip"
|
||||
- "qt-win32-4.8.2-gitian-r1.zip"
|
||||
- "boost-win32-1.50.0-gitian2.zip"
|
||||
- "bitcoin-deps-0.0.5.zip"
|
||||
script: |
|
||||
#
|
||||
mkdir $HOME/qt
|
||||
cd $HOME/qt
|
||||
unzip ../build/qt-win32-4.7.4-gitian.zip
|
||||
unzip ../build/qt-win32-4.8.2-gitian-r1.zip
|
||||
cd $HOME/build/
|
||||
export PATH=$PATH:$HOME/qt/bin/
|
||||
#
|
||||
mkdir boost_1_47_0
|
||||
cd boost_1_47_0
|
||||
mkdir boost_1_50_0
|
||||
cd boost_1_50_0
|
||||
mkdir -p stage/lib
|
||||
unzip ../boost-win32-1.47.0-gitian.zip
|
||||
unzip ../boost-win32-1.50.0-gitian2.zip
|
||||
cd bin/$GBUILD_BITS
|
||||
for lib in *; do
|
||||
i586-mingw32msvc-ar rc ../../stage/lib/libboost_${lib}-mt-s.a $lib/*.o
|
||||
@@ -39,31 +39,36 @@ script: |
|
||||
mv include/boost .
|
||||
cd ..
|
||||
#
|
||||
unzip bitcoin-deps-0.0.3.zip
|
||||
unzip bitcoin-deps-0.0.5.zip
|
||||
#
|
||||
find -type f | xargs touch --date="$REFERENCE_DATETIME"
|
||||
#
|
||||
cd bitcoin
|
||||
mkdir -p $OUTDIR/src
|
||||
cp -a . $OUTDIR/src
|
||||
rm -rf $OUTDIR/src/.git
|
||||
git archive HEAD | tar -x -C $OUTDIR/src
|
||||
cp $OUTDIR/src/doc/README_windows.txt $OUTDIR/readme.txt
|
||||
cp $OUTDIR/src/COPYING $OUTDIR/license.txt
|
||||
cp $OUTDIR/src/COPYING $OUTDIR/COPYING.txt
|
||||
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
|
||||
export FAKETIME=$REFERENCE_DATETIME
|
||||
export TZ=UTC
|
||||
$HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross USE_SSL=1 MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_47_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_47_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.0e OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.0e/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=bitcoin QMAKE_LFLAGS=-frandom-seed=bitcoin
|
||||
$HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_50_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_50_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.1c OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.1c/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=bitcoin QMAKE_LFLAGS=-frandom-seed=bitcoin USE_BUILD_INFO=1
|
||||
make $MAKEOPTS
|
||||
cp release/bitcoin-qt.exe $OUTDIR/
|
||||
#
|
||||
cd src
|
||||
sed 's/$(DEBUGFLAGS)/-frandom-seed=bitcoin/' -i makefile.linux-mingw
|
||||
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
|
||||
export FAKETIME=$REFERENCE_DATETIME
|
||||
export TZ=UTC
|
||||
make -f makefile.linux-mingw $MAKEOPTS DEPSDIR=$HOME/build bitcoind.exe USE_SSL=1 USE_UPNP=0
|
||||
make -f makefile.linux-mingw $MAKEOPTS DEPSDIR=$HOME/build bitcoind.exe USE_UPNP=0 DEBUGFLAGS="-frandom-seed=bitcoin"
|
||||
i586-mingw32msvc-strip bitcoind.exe
|
||||
makensis ../share/setup.nsi
|
||||
cp ../share/bitcoin-*-win32-setup.exe $OUTDIR/
|
||||
mkdir $OUTDIR/daemon
|
||||
cp bitcoind.exe $OUTDIR/daemon
|
||||
cd ..
|
||||
mkdir nsis
|
||||
git archive HEAD | tar -x -C nsis
|
||||
cd nsis/src
|
||||
mkdir ../release
|
||||
cp ../../release/* ../release/
|
||||
cp ../../src/*.exe .
|
||||
makensis ../share/setup.nsi
|
||||
cp ../share/bitcoin-*-win32-setup.exe $OUTDIR/
|
||||
|
||||
@@ -42,16 +42,14 @@ script: |
|
||||
#
|
||||
cd bitcoin
|
||||
mkdir -p $OUTDIR/src
|
||||
cp -a . $OUTDIR/src
|
||||
rm -rf $OUTDIR/src/.git
|
||||
git archive HEAD | tar -x -C $OUTDIR/src
|
||||
cp $OUTDIR/src/doc/README $OUTDIR
|
||||
cp $OUTDIR/src/COPYING $OUTDIR
|
||||
cd src
|
||||
sed 's/$(DEBUGFLAGS)//' -i makefile.unix
|
||||
make -f makefile.unix STATIC=1 OPENSSL_INCLUDE_PATH="$INSTDIR/include" OPENSSL_LIB_PATH="$INSTDIR/lib" $MAKEOPTS bitcoind USE_UPNP=0 USE_SSL=1
|
||||
make -f makefile.unix STATIC=1 OPENSSL_INCLUDE_PATH="$INSTDIR/include" OPENSSL_LIB_PATH="$INSTDIR/lib" $MAKEOPTS bitcoind USE_UPNP=0 DEBUGFLAGS=
|
||||
mkdir -p $OUTDIR/bin/$GBUILD_BITS
|
||||
install -s bitcoind $OUTDIR/bin/$GBUILD_BITS
|
||||
cd ..
|
||||
qmake INCLUDEPATH="$INSTDIR/include" LIBS="-L$INSTDIR/lib" RELEASE=1 USE_SSL=1 USE_QRCODE=1
|
||||
qmake INCLUDEPATH="$INSTDIR/include" LIBS="-L$INSTDIR/lib" RELEASE=1 USE_QRCODE=1
|
||||
make $MAKEOPTS
|
||||
install bitcoin-qt $OUTDIR/bin/$GBUILD_BITS
|
||||
|
||||
@@ -11,15 +11,15 @@ packages:
|
||||
reference_datetime: "2011-01-30 00:00:00"
|
||||
remotes: []
|
||||
files:
|
||||
- "qt-everywhere-opensource-src-4.7.4.tar.gz"
|
||||
- "qt-everywhere-opensource-src-4.8.2.tar.gz"
|
||||
script: |
|
||||
INSTDIR="$HOME/qt/"
|
||||
mkdir $INSTDIR
|
||||
SRCDIR="$INSTDIR/src/"
|
||||
mkdir $SRCDIR
|
||||
#
|
||||
tar xzf qt-everywhere-opensource-src-4.7.4.tar.gz
|
||||
cd qt-everywhere-opensource-src-4.7.4
|
||||
tar xzf qt-everywhere-opensource-src-4.8.2.tar.gz
|
||||
cd qt-everywhere-opensource-src-4.8.2
|
||||
sed 's/$TODAY/2011-01-30/' -i configure
|
||||
sed 's/i686-pc-mingw32-/i586-mingw32msvc-/' -i mkspecs/unsupported/win32-g++-cross/qmake.conf
|
||||
sed --posix 's|QMAKE_CFLAGS\t\t= -pipe|QMAKE_CFLAGS\t\t= -pipe -isystem /usr/i586-mingw32msvc/include/ -frandom-seed=qtbuild|' -i mkspecs/unsupported/win32-g++-cross/qmake.conf
|
||||
@@ -40,7 +40,7 @@ script: |
|
||||
#export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
|
||||
export FAKETIME=$REFERENCE_DATETIME
|
||||
export TZ=UTC
|
||||
./configure -prefix $INSTDIR -confirm-license -release -opensource -static -no-qt3support -xplatform unsupported/win32-g++-cross -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-declarative -no-script -no-scripttools -no-javascript-jit -no-webkit -no-svg -no-xmlpatterns -no-sql-sqlite -no-nis -no-cups -no-iconv -no-dbus -no-gif -no-libtiff -opengl no -nomake examples -nomake demos -nomake docs
|
||||
./configure -prefix $INSTDIR -confirm-license -release -opensource -static -no-qt3support -xplatform unsupported/win32-g++-cross -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-declarative -no-script -no-scripttools -no-javascript-jit -no-webkit -no-svg -no-xmlpatterns -no-sql-sqlite -no-nis -no-cups -no-iconv -no-dbus -no-gif -no-libtiff -no-opengl -nomake examples -nomake demos -nomake docs -no-feature-style-plastique -no-feature-style-cleanlooks -no-feature-style-motif -no-feature-style-cde -no-feature-style-windowsce -no-feature-style-windowsmobile -no-feature-style-s60
|
||||
find . -name *.prl | xargs -l sed 's|/\.||' -i
|
||||
find . -name *.prl | xargs -l sed 's|/$||' -i
|
||||
make $MAKEOPTS install
|
||||
@@ -51,4 +51,4 @@ script: |
|
||||
|
||||
# as zip stores file timestamps, use faketime to intercept stat calls to set dates for all files to reference date
|
||||
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
|
||||
zip -r $OUTDIR/qt-win32-4.7.4-gitian.zip *
|
||||
zip -r $OUTDIR/qt-win32-4.8.2-gitian-r1.zip *
|
||||
|
||||
@@ -15,9 +15,13 @@ signers:
|
||||
weight: 40
|
||||
name: Devrandom
|
||||
key: devrandom
|
||||
E463A93F5F3117EEDE6C7316BD02942421F4889F:
|
||||
weight: 40
|
||||
name: Luke-Jr
|
||||
key: luke-jr
|
||||
D762373D24904A3E42F33B08B9A408E71DAAC974:
|
||||
weight: 40
|
||||
name: Sipa
|
||||
name: "Pieter Wuille"
|
||||
key: sipa
|
||||
77E72E69DA7EE0A148C06B21B34821D4944DE5F7:
|
||||
weight: 40
|
||||
@@ -27,7 +31,7 @@ signers:
|
||||
weight: 40
|
||||
name: "Gavin Andresen"
|
||||
key: gavinandresen
|
||||
71A3B16735405025D447E8F274810B012346C9A6
|
||||
71A3B16735405025D447E8F274810B012346C9A6:
|
||||
weight: 40
|
||||
name: "Wladimir J. van der Laan"
|
||||
key: laanwj
|
||||
|
||||
BIN
contrib/gitian-downloader/luke-jr-key.pgp
Normal file
BIN
contrib/gitian-downloader/luke-jr-key.pgp
Normal file
Binary file not shown.
Binary file not shown.
@@ -15,9 +15,13 @@ signers:
|
||||
weight: 40
|
||||
name: Devrandom
|
||||
key: devrandom
|
||||
E463A93F5F3117EEDE6C7316BD02942421F4889F:
|
||||
weight: 40
|
||||
name: Luke-Jr
|
||||
key: luke-jr
|
||||
D762373D24904A3E42F33B08B9A408E71DAAC974:
|
||||
weight: 40
|
||||
name: Sipa
|
||||
name: "Pieter Wuille"
|
||||
key: sipa
|
||||
77E72E69DA7EE0A148C06B21B34821D4944DE5F7:
|
||||
weight: 40
|
||||
@@ -27,7 +31,7 @@ signers:
|
||||
weight: 40
|
||||
name: "Gavin Andresen"
|
||||
key: gavinandresen
|
||||
71A3B16735405025D447E8F274810B012346C9A6
|
||||
71A3B16735405025D447E8F274810B012346C9A6:
|
||||
weight: 40
|
||||
name: "Wladimir J. van der Laan"
|
||||
key: laanwj
|
||||
|
||||
@@ -169,6 +169,9 @@ class DeploymentInfo(object):
|
||||
elif os.path.exists(os.path.join(parentDir, "share", "qt4", "translations")):
|
||||
# MacPorts layout, e.g. "/opt/local/share/qt4"
|
||||
self.qtPath = os.path.join(parentDir, "share", "qt4")
|
||||
elif os.path.exists(os.path.join(os.path.dirname(parentDir), "share", "qt4", "translations")):
|
||||
# Newer Macports layout
|
||||
self.qtPath = os.path.join(os.path.dirname(parentDir), "share", "qt4")
|
||||
|
||||
if self.qtPath is not None:
|
||||
pluginPath = os.path.join(self.qtPath, "plugins")
|
||||
@@ -725,7 +728,7 @@ if config.dmg is not None:
|
||||
disk.close()
|
||||
if bg_path is not None:
|
||||
subprocess.call(["SetFile", "-a", "V", bg_path])
|
||||
disk.update(registering_applications=False)
|
||||
# disk.update(registering_applications=False)
|
||||
sleep(2)
|
||||
disk.eject()
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# Copyright (c) 2011 The Bitcoin developers
|
||||
# Distributed under the MIT/X11 software license, see the accompanying
|
||||
# file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#
|
||||
|
||||
import time
|
||||
|
||||
1
contrib/testgen/README
Normal file
1
contrib/testgen/README
Normal file
@@ -0,0 +1 @@
|
||||
Utilities to generate test vectors for the data-driven Bitcoin tests
|
||||
104
contrib/testgen/base58.py
Normal file
104
contrib/testgen/base58.py
Normal file
@@ -0,0 +1,104 @@
|
||||
'''
|
||||
Bitcoin base58 encoding and decoding.
|
||||
|
||||
Based on https://bitcointalk.org/index.php?topic=1026.0 (public domain)
|
||||
'''
|
||||
import hashlib
|
||||
|
||||
# for compatibility with following code...
|
||||
class SHA256:
|
||||
new = hashlib.sha256
|
||||
|
||||
if str != bytes:
|
||||
# Python 3.x
|
||||
def ord(c):
|
||||
return c
|
||||
def chr(n):
|
||||
return bytes( (n,) )
|
||||
|
||||
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||
__b58base = len(__b58chars)
|
||||
b58chars = __b58chars
|
||||
|
||||
def b58encode(v):
|
||||
""" encode v, which is a string of bytes, to base58.
|
||||
"""
|
||||
long_value = 0
|
||||
for (i, c) in enumerate(v[::-1]):
|
||||
long_value += (256**i) * ord(c)
|
||||
|
||||
result = ''
|
||||
while long_value >= __b58base:
|
||||
div, mod = divmod(long_value, __b58base)
|
||||
result = __b58chars[mod] + result
|
||||
long_value = div
|
||||
result = __b58chars[long_value] + result
|
||||
|
||||
# Bitcoin does a little leading-zero-compression:
|
||||
# leading 0-bytes in the input become leading-1s
|
||||
nPad = 0
|
||||
for c in v:
|
||||
if c == '\0': nPad += 1
|
||||
else: break
|
||||
|
||||
return (__b58chars[0]*nPad) + result
|
||||
|
||||
def b58decode(v, length = None):
|
||||
""" decode v into a string of len bytes
|
||||
"""
|
||||
long_value = 0
|
||||
for (i, c) in enumerate(v[::-1]):
|
||||
long_value += __b58chars.find(c) * (__b58base**i)
|
||||
|
||||
result = bytes()
|
||||
while long_value >= 256:
|
||||
div, mod = divmod(long_value, 256)
|
||||
result = chr(mod) + result
|
||||
long_value = div
|
||||
result = chr(long_value) + result
|
||||
|
||||
nPad = 0
|
||||
for c in v:
|
||||
if c == __b58chars[0]: nPad += 1
|
||||
else: break
|
||||
|
||||
result = chr(0)*nPad + result
|
||||
if length is not None and len(result) != length:
|
||||
return None
|
||||
|
||||
return result
|
||||
|
||||
def checksum(v):
|
||||
"""Return 32-bit checksum based on SHA256"""
|
||||
return SHA256.new(SHA256.new(v).digest()).digest()[0:4]
|
||||
|
||||
def b58encode_chk(v):
|
||||
"""b58encode a string, with 32-bit checksum"""
|
||||
return b58encode(v + checksum(v))
|
||||
|
||||
def b58decode_chk(v):
|
||||
"""decode a base58 string, check and remove checksum"""
|
||||
result = b58decode(v)
|
||||
if result is None:
|
||||
return None
|
||||
h3 = checksum(result[:-4])
|
||||
if result[-4:] == checksum(result[:-4]):
|
||||
return result[:-4]
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_bcaddress_version(strAddress):
|
||||
""" Returns None if strAddress is invalid. Otherwise returns integer version of address. """
|
||||
addr = b58decode_chk(strAddress)
|
||||
if addr is None or len(addr)!=21: return None
|
||||
version = addr[0]
|
||||
return ord(version)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Test case (from http://gitorious.org/bitcoin/python-base58.git)
|
||||
assert get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is 0
|
||||
_ohai = 'o hai'.encode('ascii')
|
||||
_tmp = b58encode(_ohai)
|
||||
assert _tmp == 'DYB3oMS'
|
||||
assert b58decode(_tmp, 5) == _ohai
|
||||
print("Tests passed")
|
||||
126
contrib/testgen/gen_base58_test_vectors.py
Executable file
126
contrib/testgen/gen_base58_test_vectors.py
Executable file
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python
|
||||
'''
|
||||
Generate valid and invalid base58 address and private key test vectors.
|
||||
|
||||
Usage:
|
||||
gen_base58_test_vectors.py valid 50 > ../../src/test/data/base58_keys_valid.json
|
||||
gen_base58_test_vectors.py invalid 50 > ../../src/test/data/base58_keys_invalid.json
|
||||
'''
|
||||
# 2012 Wladimir J. van der Laan
|
||||
# Released under MIT License
|
||||
import os
|
||||
from itertools import islice
|
||||
from base58 import b58encode, b58decode, b58encode_chk, b58decode_chk, b58chars
|
||||
import random
|
||||
from binascii import b2a_hex
|
||||
|
||||
# key types
|
||||
PUBKEY_ADDRESS = 0
|
||||
SCRIPT_ADDRESS = 5
|
||||
PUBKEY_ADDRESS_TEST = 111
|
||||
SCRIPT_ADDRESS_TEST = 196
|
||||
PRIVKEY = 128
|
||||
PRIVKEY_TEST = 239
|
||||
|
||||
metadata_keys = ['isPrivkey', 'isTestnet', 'addrType', 'isCompressed']
|
||||
# templates for valid sequences
|
||||
templates = [
|
||||
# prefix, payload_size, suffix, metadata
|
||||
# None = N/A
|
||||
((PUBKEY_ADDRESS,), 20, (), (False, False, 'pubkey', None)),
|
||||
((SCRIPT_ADDRESS,), 20, (), (False, False, 'script', None)),
|
||||
((PUBKEY_ADDRESS_TEST,), 20, (), (False, True, 'pubkey', None)),
|
||||
((SCRIPT_ADDRESS_TEST,), 20, (), (False, True, 'script', None)),
|
||||
((PRIVKEY,), 32, (), (True, False, None, False)),
|
||||
((PRIVKEY,), 32, (1,), (True, False, None, True)),
|
||||
((PRIVKEY_TEST,), 32, (), (True, True, None, False)),
|
||||
((PRIVKEY_TEST,), 32, (1,), (True, True, None, True))
|
||||
]
|
||||
|
||||
def is_valid(v):
|
||||
'''Check vector v for validity'''
|
||||
result = b58decode_chk(v)
|
||||
if result is None:
|
||||
return False
|
||||
valid = False
|
||||
for template in templates:
|
||||
prefix = str(bytearray(template[0]))
|
||||
suffix = str(bytearray(template[2]))
|
||||
if result.startswith(prefix) and result.endswith(suffix):
|
||||
if (len(result) - len(prefix) - len(suffix)) == template[1]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def gen_valid_vectors():
|
||||
'''Generate valid test vectors'''
|
||||
while True:
|
||||
for template in templates:
|
||||
prefix = str(bytearray(template[0]))
|
||||
payload = os.urandom(template[1])
|
||||
suffix = str(bytearray(template[2]))
|
||||
rv = b58encode_chk(prefix + payload + suffix)
|
||||
assert is_valid(rv)
|
||||
metadata = dict([(x,y) for (x,y) in zip(metadata_keys,template[3]) if y is not None])
|
||||
yield (rv, b2a_hex(payload), metadata)
|
||||
|
||||
def gen_invalid_vector(template, corrupt_prefix, randomize_payload_size, corrupt_suffix):
|
||||
'''Generate possibly invalid vector'''
|
||||
if corrupt_prefix:
|
||||
prefix = os.urandom(1)
|
||||
else:
|
||||
prefix = str(bytearray(template[0]))
|
||||
|
||||
if randomize_payload_size:
|
||||
payload = os.urandom(max(int(random.expovariate(0.5)), 50))
|
||||
else:
|
||||
payload = os.urandom(template[1])
|
||||
|
||||
if corrupt_suffix:
|
||||
suffix = os.urandom(len(template[2]))
|
||||
else:
|
||||
suffix = str(bytearray(template[2]))
|
||||
|
||||
return b58encode_chk(prefix + payload + suffix)
|
||||
|
||||
def randbool(p = 0.5):
|
||||
'''Return True with P(p)'''
|
||||
return random.random() < p
|
||||
|
||||
def gen_invalid_vectors():
|
||||
'''Generate invalid test vectors'''
|
||||
# start with some manual edge-cases
|
||||
yield "",
|
||||
yield "x",
|
||||
while True:
|
||||
# kinds of invalid vectors:
|
||||
# invalid prefix
|
||||
# invalid payload length
|
||||
# invalid (randomized) suffix (add random data)
|
||||
# corrupt checksum
|
||||
for template in templates:
|
||||
val = gen_invalid_vector(template, randbool(0.2), randbool(0.2), randbool(0.2))
|
||||
if random.randint(0,10)<1: # line corruption
|
||||
if randbool(): # add random character to end
|
||||
val += random.choice(b58chars)
|
||||
else: # replace random character in the middle
|
||||
n = random.randint(0, len(val))
|
||||
val = val[0:n] + random.choice(b58chars) + val[n+1:]
|
||||
if not is_valid(val):
|
||||
yield val,
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys, json
|
||||
iters = {'valid':gen_valid_vectors, 'invalid':gen_invalid_vectors}
|
||||
try:
|
||||
uiter = iters[sys.argv[1]]
|
||||
except IndexError:
|
||||
uiter = gen_valid_vectors
|
||||
try:
|
||||
count = int(sys.argv[2])
|
||||
except IndexError:
|
||||
count = 0
|
||||
|
||||
data = list(islice(uiter(), count))
|
||||
json.dump(data, sys.stdout, sort_keys=True, indent=4)
|
||||
sys.stdout.write('\n')
|
||||
|
||||
@@ -203,7 +203,7 @@ TAB_SIZE = 8
|
||||
# For example adding "sideeffect=\par Side Effects:\n" will allow you to
|
||||
# put the command \sideeffect (or @sideeffect) in the documentation, which
|
||||
# will result in a user-defined paragraph with heading "Side Effects:".
|
||||
# You can put \n's in the value part of an alias to insert newlines.
|
||||
# You can put \n in the value part of an alias to insert newlines.
|
||||
|
||||
ALIASES =
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
Bitcoin 0.6.0 BETA
|
||||
Bitcoin 0.7.1 BETA
|
||||
|
||||
Copyright (c) 2009-2012 Bitcoin Developers
|
||||
Distributed under the MIT/X11 software license, see the accompanying
|
||||
file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
This product includes software developed by the OpenSSL Project for use in
|
||||
the OpenSSL Toolkit (http://www.openssl.org/). This product includes
|
||||
cryptographic software written by Eric Young (eay@cryptsoft.com).
|
||||
@@ -18,7 +18,7 @@ with each other, with the help of a P2P network to check for double-spending.
|
||||
|
||||
Setup
|
||||
-----
|
||||
You need the Qt4 run-time libraries to run bitcoin-qt. On Debian or Ubuntu:
|
||||
You need the Qt4 run-time libraries to run Bitcoin-Qt. On Debian or Ubuntu:
|
||||
sudo apt-get install libqtgui4
|
||||
|
||||
Unpack the files into a directory and run:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
Bitcoin 0.6.0 BETA
|
||||
Bitcoin 0.7.1 BETA
|
||||
|
||||
Copyright (c) 2009-2012 Bitcoin Developers
|
||||
Distributed under the MIT/X11 software license, see the accompanying
|
||||
file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
This product includes software developed by the OpenSSL Project for use in
|
||||
the OpenSSL Toolkit (http://www.openssl.org/). This product includes
|
||||
cryptographic software written by Eric Young (eay@cryptsoft.com).
|
||||
|
||||
92
doc/Tor.txt
Normal file
92
doc/Tor.txt
Normal file
@@ -0,0 +1,92 @@
|
||||
TOR SUPPORT IN BITCOIN
|
||||
======================
|
||||
|
||||
It is possible to run Bitcoin as a Tor hidden service, and connect to such services.
|
||||
|
||||
The following assumes you have a Tor proxy running on port 9050. Many distributions
|
||||
default to having a SOCKS proxy listening on port 9050, but others may not.
|
||||
In particular, the Tor Browser Bundle defaults to listening on a random port. See
|
||||
https://www.torproject.org/docs/faq.html.en#TBBSocksPort for how to properly
|
||||
configure Tor.
|
||||
|
||||
|
||||
1. Run bitcoin behind a Tor proxy
|
||||
---------------------------------
|
||||
|
||||
The first step is running Bitcoin behind a Tor proxy. This will already make all
|
||||
outgoing connections be anonimized, but more is possible.
|
||||
|
||||
-socks=5 SOCKS5 supports connecting-to-hostname, which can be used instead
|
||||
of doing a (leaking) local DNS lookup. SOCKS5 is the default,
|
||||
but SOCKS4 does not support this. (SOCKS4a does, but isn't
|
||||
implemented).
|
||||
|
||||
-proxy=ip:port Set the proxy server. If SOCKS5 is selected (default), this proxy
|
||||
server will be used to try to reach .onion addresses as well.
|
||||
|
||||
-tor=ip:port Set the proxy server to use for tor hidden services. You do not
|
||||
need to set this if it's the same as -proxy. You can use -notor
|
||||
to explicitly disable access to hidden service.
|
||||
|
||||
-listen When using -proxy, listening is disabled by default. If you want
|
||||
to run a hidden service (see next section), you'll need to enable
|
||||
it explicitly.
|
||||
|
||||
-connect=X When behind a Tor proxy, you can specify .onion addresses instead
|
||||
-addnode=X of IP addresses or hostnames in these parameters. It requires
|
||||
-seednode=X SOCKS5. In Tor mode, such addresses can also be exchanged with
|
||||
other P2P nodes.
|
||||
|
||||
In a typical situation, this suffices to run behind a Tor proxy:
|
||||
|
||||
./bitcoin -proxy=127.0.0.1:9050
|
||||
|
||||
|
||||
2. Run a bitcoin hidden server
|
||||
------------------------------
|
||||
|
||||
If you configure your Tor system accordingly, it is possible to make your node also
|
||||
reachable from the Tor network. Add these lines to your /etc/tor/torrc (or equivalent
|
||||
config file):
|
||||
|
||||
HiddenServiceDir /var/lib/tor/bitcoin-service/
|
||||
HiddenServicePort 8333 127.0.0.1:8333
|
||||
|
||||
The directory can be different of course, but (both) port numbers should be equal to
|
||||
your bitcoind's P2P listen port (8333 by default).
|
||||
|
||||
-externalip=X You can tell bitcoin about its publicly reachable address using
|
||||
this option, and this can be a .onion address. Given the above
|
||||
configuration, you can find your onion address in
|
||||
/var/lib/tor/bitcoin-service/hostname. Onion addresses are given
|
||||
preference for your node to advertize itself with, for connections
|
||||
coming from unroutable addresses (such as 127.0.0.1, where the
|
||||
Tor proxy typically runs).
|
||||
|
||||
-listen You'll need to enable listening for incoming connections, as this
|
||||
is off by default behind a proxy.
|
||||
|
||||
-discover When -externalip is specified, no attempt is made to discover local
|
||||
IPv4 or IPv6 addresses. If you want to run a dual stack, reachable
|
||||
from both Tor and IPv4 (or IPv6), you'll need to either pass your
|
||||
other addresses using -externalip, or explicitly enable -discover.
|
||||
Note that both addresses of a dual-stack system may be easily
|
||||
linkable using traffic analysis.
|
||||
|
||||
In a typical situation, where you're only reachable via Tor, this should suffice:
|
||||
|
||||
./bitcoind -proxy=127.0.0.1:9050 -externalip=57qr3yd1nyntf5k.onion -listen
|
||||
|
||||
(obviously replace the Onion address with your own). If you don't care too much
|
||||
about hiding your node, and want to be reachable on IPv4 as well, additionally
|
||||
specify:
|
||||
|
||||
./bitcoind ... -discover
|
||||
|
||||
and open port 8333 on your firewall (or use -upnp).
|
||||
|
||||
If you only want to use Tor to reach onion addresses, but not use it as a proxy
|
||||
for normal IPv4/IPv6 communication, use:
|
||||
|
||||
./bitcoin -tor=127.0.0.1:9050 -externalip=57qr3yd1nyntf5k.onion -discover
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
Code: src/strlcpy.h
|
||||
Author: Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
License: ISC
|
||||
|
||||
Icon: src/qt/res/icons/clock*.png, src/qt/res/icons/tx*.png,
|
||||
src/qt/res/src/*.svg
|
||||
Designer: Wladimir van der Laan
|
||||
@@ -22,9 +26,10 @@ Site: http://findicons.com/icon/93743/blocks_gnome_netstatus_0
|
||||
|
||||
Icon: src/qt/res/icons/transaction*.png
|
||||
Designer: md2k7
|
||||
Site: https://forum.bitcoin.org/index.php?topic=15276.0
|
||||
Site: https://bitcointalk.org/index.php?topic=15276.0
|
||||
License: You are free to do with these icons as you wish, including selling,
|
||||
copying, modifying etc.
|
||||
License: MIT
|
||||
|
||||
Icon: src/qt/res/icons/configure.png, src/qt/res/icons/quit.png,
|
||||
src/qt/res/icons/editcopy.png, src/qt/res/icons/editpaste.png,
|
||||
@@ -37,7 +42,7 @@ License: LGPL
|
||||
Icon: src/qt/res/icons/bitcoin.png, src/qt/res/icons/toolbar.png
|
||||
Designer: Bitboy (optimized for 16x16 by Wladimir van der Laan)
|
||||
License: Public Domain
|
||||
Site: http://forum.bitcoin.org/?topic=1756.0
|
||||
Site: https://bitcointalk.org/?topic=1756.0
|
||||
|
||||
Icon: scripts/img/reload.xcf (modified),src/qt/res/movies/update_spinner.mng
|
||||
Icon Pack: Kids
|
||||
@@ -50,3 +55,7 @@ Designer: Crobbo (forum)
|
||||
Site: https://bitcointalk.org/index.php?topic=32273.0
|
||||
License: Public domain
|
||||
|
||||
Icon: src/qt/res/icons/debugwindow.png
|
||||
Designer: Vignoni David
|
||||
Site: http://www.oxygen-icons.org/
|
||||
License: Oxygen icon theme is dual licensed. You may copy it under the Creative Common Attribution-ShareAlike 3.0 License or the GNU Library General Public License.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
Copyright (c) 2009-2012 Bitcoin Developers
|
||||
Distributed under the MIT/X11 software license, see the accompanying
|
||||
file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
This product includes software developed by the OpenSSL Project for use in
|
||||
the OpenSSL Toolkit (http://www.openssl.org/). This product includes
|
||||
cryptographic software written by Eric Young (eay@cryptsoft.com) and UPnP
|
||||
software written by Thomas Bernard.
|
||||
|
||||
|
||||
See readme-qt.rst for instructions on building Bitcoin QT, the
|
||||
See readme-qt.rst for instructions on building Bitcoin-Qt, the
|
||||
graphical user interface.
|
||||
|
||||
WINDOWS BUILD NOTES
|
||||
@@ -24,9 +24,9 @@ Dependencies
|
||||
Libraries you need to download separately and build:
|
||||
|
||||
default path download
|
||||
OpenSSL \openssl-1.0.0d-mgw http://www.openssl.org/source/
|
||||
OpenSSL \openssl-1.0.1c-mgw http://www.openssl.org/source/
|
||||
Berkeley DB \db-4.8.30.NC-mgw http://www.oracle.com/technology/software/products/berkeley-db/index.html
|
||||
Boost \boost-1.47.0-mgw http://www.boost.org/users/download/
|
||||
Boost \boost-1.50.0-mgw http://www.boost.org/users/download/
|
||||
miniupnpc \miniupnpc-1.6-mgw http://miniupnp.tuxfamily.org/files/
|
||||
|
||||
Their licenses:
|
||||
@@ -36,9 +36,9 @@ Boost MIT-like license
|
||||
miniupnpc New (3-clause) BSD license
|
||||
|
||||
Versions used in this release:
|
||||
OpenSSL 1.0.0e
|
||||
OpenSSL 1.0.1c
|
||||
Berkeley DB 4.8.30.NC
|
||||
Boost 1.47.0
|
||||
Boost 1.50.0
|
||||
miniupnpc 1.6
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ MSYS shell:
|
||||
un-tar sources with MSYS 'tar xfz' to avoid issue with symlinks (OpenSSL ticket 2377)
|
||||
change 'MAKE' env. variable from 'C:\MinGW32\bin\mingw32-make.exe' to '/c/MinGW32/bin/mingw32-make.exe'
|
||||
|
||||
cd /c/openssl-1.0.0e-mgw
|
||||
cd /c/openssl-1.0.1c-mgw
|
||||
./config
|
||||
make
|
||||
|
||||
@@ -63,7 +63,7 @@ Boost
|
||||
-----
|
||||
DOS prompt:
|
||||
downloaded boost jam 3.1.18
|
||||
cd \boost-1.47.0-mgw
|
||||
cd \boost-1.50.0-mgw
|
||||
bjam toolset=gcc --build-type=complete stage
|
||||
|
||||
MiniUPnPc
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
Copyright (c) 2009-2012 Bitcoin Developers
|
||||
Distributed under the MIT/X11 software license, see the accompanying file
|
||||
license.txt or http://www.opensource.org/licenses/mit-license.php. This
|
||||
product includes software developed by the OpenSSL Project for use in the
|
||||
OpenSSL Toolkit (http://www.openssl.org/). This product includes cryptographic
|
||||
software written by Eric Young (eay@cryptsoft.com) and UPnP software written by
|
||||
Thomas Bernard.
|
||||
Distributed under the MIT/X11 software license, see the accompanying
|
||||
file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
This product includes software developed by the OpenSSL Project for use in
|
||||
the OpenSSL Toolkit (http://www.openssl.org/). This product includes
|
||||
cryptographic software written by Eric Young (eay@cryptsoft.com) and UPnP
|
||||
software written by Thomas Bernard.
|
||||
|
||||
|
||||
Mac OS X bitcoind build instructions
|
||||
@@ -12,17 +12,17 @@ Laszlo Hanyecz <solar@heliacal.net>
|
||||
Douglas Huff <dhuff@jrbobdobbs.org>
|
||||
|
||||
|
||||
See readme-qt.rst for instructions on building Bitcoin QT, the
|
||||
See readme-qt.rst for instructions on building Bitcoin-Qt, the
|
||||
graphical user interface.
|
||||
|
||||
Tested on 10.5 and 10.6 intel. PPC is not supported because it's big-endian.
|
||||
Tested on 10.5, 10.6 and 10.7 intel. PPC is not supported because it's big-endian.
|
||||
|
||||
All of the commands should be executed in Terminal.app.. it's in
|
||||
/Applications/Utilities
|
||||
|
||||
You need to install XCode with all the options checked so that the compiler and
|
||||
everything is available in /usr not just /Developer I think it comes on the DVD
|
||||
but you can get the current version from http://developer.apple.com
|
||||
everything is available in /usr not just /Developer. XCode should be available on your OS X
|
||||
install DVD, but if not, you can get the current version from https://developer.apple.com/xcode/
|
||||
|
||||
|
||||
1. Clone the github tree to get the source code:
|
||||
@@ -44,7 +44,7 @@ sudo port install qrencode
|
||||
4. Now you should be able to build bitcoind:
|
||||
|
||||
cd bitcoin/src
|
||||
make -f makefile.osx
|
||||
make -f makefile.osx USE_IPV6=1
|
||||
|
||||
Run:
|
||||
./bitcoind --help # for a list of command-line options.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Copyright (c) 2009-2012 Bitcoin Developers
|
||||
Distributed under the MIT/X11 software license, see the accompanying
|
||||
file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
This product includes software developed by the OpenSSL Project for use in
|
||||
the OpenSSL Toolkit (http://www.openssl.org/). This product includes
|
||||
cryptographic software written by Eric Young (eay@cryptsoft.com) and UPnP
|
||||
@@ -16,8 +16,8 @@ To Build
|
||||
cd src/
|
||||
make -f makefile.unix # Headless bitcoin
|
||||
|
||||
See readme-qt.rst for instructions on building Bitcoin QT,
|
||||
the graphical bitcoin.
|
||||
See readme-qt.rst for instructions on building Bitcoin-Qt,
|
||||
the graphical user interface.
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
@@ -28,20 +28,16 @@ Dependencies
|
||||
libdb4.8 Berkeley DB Blockchain & wallet storage
|
||||
libboost Boost C++ Library
|
||||
miniupnpc UPnP Support Optional firewall-jumping support
|
||||
libqrencode QRCode generation Optional QRCode generation
|
||||
|
||||
miniupnpc may be used for UPnP port mapping. It can be downloaded from
|
||||
http://miniupnp.tuxfamily.org/files/. UPnP support is compiled in and
|
||||
turned off by default. Set USE_UPNP to a different value to control this:
|
||||
USE_UPNP= No UPnP support - miniupnp not required
|
||||
USE_UPNP=- No UPnP support - miniupnp not required
|
||||
USE_UPNP=0 (the default) UPnP support turned off by default at runtime
|
||||
USE_UPNP=1 UPnP support turned on by default at runtime
|
||||
|
||||
libqrencode may be used for QRCode image generation. It can be downloaded
|
||||
from http://fukuchi.org/works/qrencode/index.html.en, or installed via
|
||||
your package manager. Set USE_QRCODE to control this:
|
||||
USE_QRCODE=0 (the default) No QRCode support - libarcode not required
|
||||
USE_QRCODE=1 QRCode support enabled
|
||||
IPv6 support may be enabled by setting:
|
||||
USE_IPV6=1 Enable IPv6 support
|
||||
|
||||
Licenses of statically linked libraries:
|
||||
Berkeley DB New BSD license with additional requirement that linked
|
||||
@@ -51,22 +47,34 @@ Licenses of statically linked libraries:
|
||||
|
||||
Versions used in this release:
|
||||
GCC 4.3.3
|
||||
OpenSSL 0.9.8g
|
||||
OpenSSL 1.0.1c
|
||||
Berkeley DB 4.8.30.NC
|
||||
Boost 1.37
|
||||
miniupnpc 1.6
|
||||
|
||||
Dependency Build Instructions: Ubuntu & Debian
|
||||
----------------------------------------------
|
||||
sudo apt-get install build-essential
|
||||
sudo apt-get install libssl-dev
|
||||
sudo apt-get install libdb4.8-dev
|
||||
sudo apt-get install libdb4.8++-dev
|
||||
Boost 1.40+: sudo apt-get install libboost-all-dev
|
||||
or Boost 1.37: sudo apt-get install libboost1.37-dev
|
||||
sudo apt-get install libqrencode-dev
|
||||
Build requirements:
|
||||
sudo apt-get install build-essential
|
||||
sudo apt-get install libssl-dev
|
||||
|
||||
If using Boost 1.37, append -mt to the boost libraries in the makefile.
|
||||
for Ubuntu 12.04:
|
||||
sudo apt-get install libboost-all-dev
|
||||
|
||||
db4.8 packages are available at:
|
||||
https://launchpad.net/~bitcoin/+archive/bitcoin
|
||||
|
||||
Ubuntu precise has packages for libdb5.1-dev and libdb5.1++-dev,
|
||||
but using these will break binary wallet compatibility, and is not recommended.
|
||||
|
||||
for other Ubuntu & Debian:
|
||||
sudo apt-get install libdb4.8-dev
|
||||
sudo apt-get install libdb4.8++-dev
|
||||
sudo apt-get install libboost1.37-dev
|
||||
(If using Boost 1.37, append -mt to the boost libraries in the makefile)
|
||||
|
||||
Optional:
|
||||
sudo apt-get install libminiupnpc-dev (see USE_UPNP compile flag)
|
||||
|
||||
|
||||
Dependency Build Instructions: Gentoo
|
||||
@@ -80,7 +88,7 @@ emerge -av1 --noreplace boost glib openssl sys-libs/db:4.8
|
||||
|
||||
Take the following steps to build (no UPnP support):
|
||||
cd ${BITCOIN_DIR}/src
|
||||
make -f makefile.unix USE_UPNP= BDB_INCLUDE_PATH='/usr/include/db4.8'
|
||||
make -f makefile.unix USE_UPNP= USE_IPV6=1 BDB_INCLUDE_PATH='/usr/include/db4.8'
|
||||
strip bitcoind
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ bn CBigNum
|
||||
Locking/mutex usage notes
|
||||
|
||||
The code is multi-threaded, and uses mutexes and the
|
||||
CRITICAL_BLOCK/TRY_CRITICAL_BLOCK macros to protect data structures.
|
||||
LOCK/TRY_LOCK macros to protect data structures.
|
||||
|
||||
Deadlocks due to inconsistent lock ordering (thread 1 locks cs_main
|
||||
and then cs_wallet, while thread 2 locks them in the opposite order:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Bitcoin-qt: Qt4 GUI for Bitcoin
|
||||
Bitcoin-Qt: Qt4 GUI for Bitcoin
|
||||
===============================
|
||||
|
||||
Build instructions
|
||||
@@ -23,25 +23,26 @@ then execute the following:
|
||||
qmake
|
||||
make
|
||||
|
||||
Alternatively, install Qt Creator and open the `bitcoin-qt.pro` file.
|
||||
Alternatively, install `Qt Creator`_ and open the `bitcoin-qt.pro` file.
|
||||
|
||||
An executable named `bitcoin-qt` will be built.
|
||||
|
||||
.. _`Qt Creator`: http://qt-project.org/downloads/
|
||||
|
||||
Windows
|
||||
--------
|
||||
|
||||
Windows build instructions:
|
||||
|
||||
- Download the `QT Windows SDK`_ and install it. You don't need the Symbian stuff, just the desktop Qt.
|
||||
- Download the `Qt Windows SDK`_ and install it. You don't need the Symbian stuff, just the desktop Qt.
|
||||
|
||||
- Download and extract the `dependencies archive`_ [#]_, or compile openssl, boost and dbcxx yourself.
|
||||
|
||||
- Copy the contents of the folder "deps" to "X:\\QtSDK\\mingw", replace X:\\ with the location where you installed the Qt SDK. Make sure that the contents of "deps\\include" end up in the current "include" directory.
|
||||
|
||||
- Open the .pro file in QT creator and build as normal (ctrl-B)
|
||||
- Open the bitcoin-qt.pro file in Qt Creator and build as normal (ctrl-B)
|
||||
|
||||
.. _`QT Windows SDK`: http://qt.nokia.com/downloads/sdk-windows-cpp
|
||||
.. _`Qt Windows SDK`: http://qt-project.org/downloads/
|
||||
.. _`dependencies archive`: https://download.visucore.com/bitcoin/qtgui_deps_1.zip
|
||||
.. [#] PGP signature: https://download.visucore.com/bitcoin/qtgui_deps_1.zip.sig (signed with RSA key ID `610945D0`_)
|
||||
.. _`610945D0`: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x610945D0
|
||||
@@ -61,16 +62,16 @@ Mac OS X
|
||||
sudo port selfupdate
|
||||
sudo port install boost db48 miniupnpc
|
||||
|
||||
- Open the .pro file in Qt Creator and build as normal (cmd-B)
|
||||
- Open the bitcoin-qt.pro file in Qt Creator and build as normal (cmd-B)
|
||||
|
||||
.. _`Qt Mac OS X SDK`: http://qt.nokia.com/downloads/sdk-mac-os-cpp
|
||||
.. _`Qt Mac OS X SDK`: http://qt-project.org/downloads/
|
||||
.. _`MacPorts`: http://www.macports.org/install.php
|
||||
|
||||
|
||||
Build configuration options
|
||||
============================
|
||||
|
||||
UPNnP port forwarding
|
||||
UPnP port forwarding
|
||||
---------------------
|
||||
|
||||
To use UPnP for port forwarding behind a NAT router (recommended, as more connections overall allow for a faster and more stable bitcoin experience), pass the following argument to qmake:
|
||||
@@ -107,8 +108,8 @@ FreeDesktop notification interface through DBUS using the following qmake option
|
||||
Generation of QR codes
|
||||
-----------------------
|
||||
|
||||
libqrencode may be used to generate QRCode images for payment requests.
|
||||
It can be downloaded from http://fukuchi.org/works/qrencode/index.html.en, or installed via your package manager. Pass the USE_QRCODE
|
||||
libqrencode may be used to generate QRCode images for payment requests.
|
||||
It can be downloaded from http://fukuchi.org/works/qrencode/index.html.en, or installed via your package manager. Pass the USE_QRCODE
|
||||
flag to qmake to control this:
|
||||
|
||||
+--------------+--------------------------------------------------------------------------+
|
||||
|
||||
73
doc/release-notes.txt
Normal file
73
doc/release-notes.txt
Normal file
@@ -0,0 +1,73 @@
|
||||
(note: this is a temporary file, to be added-to by anybody, and deleted at
|
||||
release time)
|
||||
|
||||
Building this from
|
||||
|
||||
$ git shortlog --no-merges v0.7.0..
|
||||
|
||||
How to Upgrade
|
||||
--------------
|
||||
|
||||
If you are running an older version, shut it down. Wait
|
||||
until it has completely shut down (which might take a few minutes for older
|
||||
versions), then run the installer (on Windows) or just copy over
|
||||
/Applications/Bitcoin-Qt (on Mac) or bitcoind/bitcoin-qt (on Linux).
|
||||
|
||||
If you were running on Linux with a version that might have been compiled
|
||||
with a different version of Berkeley DB (for example, if you were using an
|
||||
Ubuntu PPA version), then run the old version again with the -detachdb
|
||||
argument and shut it down; if you do not, then the new version will not
|
||||
be able to read the database files and will exit with an error.
|
||||
|
||||
Explanation of -detachdb (and the new "stop true" RPC command):
|
||||
The Berkeley DB database library stores data in both ".dat" and
|
||||
"log" files, so the database is always in a consistent state,
|
||||
even in case of power failure or other sudden shutdown. The
|
||||
format of the ".dat" files is portable between different
|
||||
versions of Berkeley DB, but the "log" files are not-- even minor
|
||||
version differences may have incompatible "log" files. The
|
||||
-detachdb option moves any pending changes from the "log" files
|
||||
to the "blkindex.dat" file for maximum compatibility, but makes
|
||||
shutdown much slower. Note that the "wallet.dat" file is always
|
||||
detached, and versions prior to 0.6.0 detached all databases
|
||||
at shutdown.
|
||||
|
||||
New features
|
||||
------------
|
||||
|
||||
* Added a boolean argument to the RPC 'stop' command, if true sets
|
||||
-detachdb to create standalone database .dat files before shutting down.
|
||||
|
||||
* -salvagewallet command-line option, which moves any existing wallet.dat
|
||||
to wallet.{timestamp}.dat and then attempts to salvage public/private
|
||||
keys and master encryption keys (if the wallet is encrypted) into
|
||||
a new wallet.dat. This should only be used if your wallet becomes
|
||||
corrupted, and is not intended to replace regular wallet backups.
|
||||
|
||||
* Import $DataDir/bootstrap.dat automatically, if it exists.
|
||||
|
||||
Dependency changes
|
||||
------------------
|
||||
|
||||
* Qt 4.8.2 for Windows builds
|
||||
|
||||
* openssl 1.0.1c
|
||||
|
||||
Bug fixes
|
||||
---------
|
||||
|
||||
* When running -testnet, use RPC port 18332 by default.
|
||||
|
||||
* Better detection and handling of corrupt wallet.dat and blkindex.dat files.
|
||||
Previous versions would crash with a DB_RUNRECOVERY exception, this
|
||||
version detects most problems and tells you how to recover if it
|
||||
cannot recover itself.
|
||||
|
||||
* Fixed an uninitialized variable bug that could cause transactions to
|
||||
be reported out of order.
|
||||
|
||||
* Fixed a bug that could cause occasional crashes on exit.
|
||||
|
||||
* Warn the user that they need to create fresh wallet backups after they
|
||||
encrypt their wallet.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
* update (commit) version in sources
|
||||
bitcoin-qt.pro
|
||||
src/main.h (CLIENT_VERSION : PROTOCOL_VERSION in serialize.h is updated only on protocol changes)
|
||||
src/clientversion.h
|
||||
share/setup.nsi
|
||||
doc/README*
|
||||
|
||||
@@ -21,23 +21,23 @@
|
||||
export VERSION=0.5.1
|
||||
cd ./gitian-builder
|
||||
|
||||
* Fetch and build inputs:
|
||||
* Fetch and build inputs: (first time, or when dependency versions change)
|
||||
mkdir -p inputs; cd inputs/
|
||||
wget 'http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.6.tar.gz' -O miniupnpc-1.6.tar.gz
|
||||
wget 'http://www.openssl.org/source/openssl-1.0.0e.tar.gz'
|
||||
wget 'http://www.openssl.org/source/openssl-1.0.1c.tar.gz'
|
||||
wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
|
||||
wget 'http://zlib.net/zlib-1.2.6.tar.gz'
|
||||
wget 'ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.9.tar.gz'
|
||||
wget 'http://fukuchi.org/works/qrencode/qrencode-3.2.0.tar.bz2'
|
||||
wget 'http://downloads.sourceforge.net/project/boost/boost/1.47.0/boost_1_47_0.tar.bz2'
|
||||
wget 'http://download.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.tar.gz'
|
||||
wget 'http://downloads.sourceforge.net/project/boost/boost/1.50.0/boost_1_50_0.tar.bz2'
|
||||
wget 'http://releases.qt-project.org/qt4/source/qt-everywhere-opensource-src-4.8.2.tar.gz'
|
||||
cd ..
|
||||
./bin/gbuild ../bitcoin/contrib/gitian-descriptors/boost-win32.yml
|
||||
cp build/out/boost-win32-1.47.0-gitian.zip inputs/
|
||||
mv build/out/boost-win32-1.50.0-gitian2.zip inputs/
|
||||
./bin/gbuild ../bitcoin/contrib/gitian-descriptors/qt-win32.yml
|
||||
cp build/out/qt-win32-4.7.4-gitian.zip inputs/
|
||||
mv build/out/qt-win32-4.8.2-gitian-r1.zip inputs/
|
||||
./bin/gbuild ../bitcoin/contrib/gitian-descriptors/deps-win32.yml
|
||||
cp build/out/bitcoin-deps-0.0.3.zip inputs/
|
||||
mv build/out/bitcoin-deps-0.0.5.zip inputs/
|
||||
|
||||
* Build bitcoind and bitcoin-qt on Linux32, Linux64, and Win32:
|
||||
./bin/gbuild --commit bitcoin=v${VERSION} ../bitcoin/contrib/gitian-descriptors/gitian.yml
|
||||
@@ -79,7 +79,7 @@
|
||||
Gavin also had trouble with the macports py27-appscript package; he
|
||||
ended up installing a version that worked with: /usr/bin/easy_install-2.7 appscript
|
||||
|
||||
qmake RELEASE=1 USE_SSL=1 USE_UPNP=1 USE_QRCODE=1 bitcoin-qt.pro
|
||||
qmake RELEASE=1 USE_UPNP=1 USE_QRCODE=1 bitcoin-qt.pro
|
||||
make
|
||||
export QTDIR=/opt/local/share/qt4 # needed to find translations/qt_*.qm files
|
||||
T=$(contrib/qt_translations.py $QTDIR/translations src/qt/locale)
|
||||
@@ -93,11 +93,14 @@
|
||||
* create SHA256SUMS for builds, and PGP-sign it
|
||||
|
||||
* update bitcoin.org version
|
||||
make sure all OS download links go to the right versions
|
||||
|
||||
* update forum version
|
||||
|
||||
* update wiki download links
|
||||
|
||||
* update wiki changelog: https://en.bitcoin.it/wiki/Changelog
|
||||
|
||||
* Commit your signature to gitian.sigs:
|
||||
pushd gitian.sigs
|
||||
git add ${VERSION}/${SIGNER}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Translations
|
||||
============
|
||||
|
||||
The QT GUI can be easily be translated into other languages. Here's how we
|
||||
The Qt GUI can be easily translated into other languages. Here's how we
|
||||
handle those translations.
|
||||
|
||||
Files and Folders
|
||||
@@ -28,36 +28,78 @@ This directory contains all translations. Filenames must adhere to this format:
|
||||
|
||||
bitcoin_xx_YY.ts or bitcoin_xx.ts
|
||||
|
||||
#### Source file
|
||||
#### bitcoin_en.ts (Source file)
|
||||
|
||||
`src/qt/locale/bitcoin_en.ts` is a treated in a special way. It is used as the
|
||||
source for all other translations. Whenever a string in the code is change
|
||||
this file must be updated to reflect those changes. Usually, this can be
|
||||
accomplished by running `lupdate`
|
||||
`src/qt/locale/bitcoin_en.ts` is treated in a special way. It is used as the
|
||||
source for all other translations. Whenever a string in the code is changed
|
||||
this file must be updated to reflect those changes. This can be accomplished
|
||||
by running `lupdate` (included in the Qt SDK). Also, a custom script is used
|
||||
to extract strings from the non-Qt parts. This script makes use of `gettext`,
|
||||
so make sure that utility is installed (ie, `apt-get install gettext` on
|
||||
Ubuntu/Debian):
|
||||
|
||||
Syncing with transifex
|
||||
python share/qt/extract_strings_qt.py
|
||||
lupdate bitcoin-qt.pro -no-obsolete -locations relative -ts src/qt/locale/bitcoin_en.ts
|
||||
|
||||
##### Handling of plurals in the source file
|
||||
|
||||
When new plurals are added to the source file, it's important to do the following steps:
|
||||
|
||||
1. Open bitcoin_en.ts in Qt Linguist (also included in the Qt SDK)
|
||||
2. Search for `%n`, which will take you to the parts in the translation that use plurals
|
||||
3. Look for empty `English Translation (Singular)` and `English Translation (Plural)` fields
|
||||
4. Add the appropriate strings for the singular and plural form of the base string
|
||||
5. Mark the item as done (via the green arrow symbol in the toolbar)
|
||||
6. Repeat from step 2. until all singular and plural forms are in the source file
|
||||
7. Save the source file
|
||||
|
||||
##### Creating the pull-request
|
||||
|
||||
An updated source file should be merged to github and Transifex will pick it
|
||||
up from there (can take some hours). Afterwards the new strings show up as "Remaining"
|
||||
in Transifex and can be translated.
|
||||
|
||||
To create the pull-request you have to do:
|
||||
|
||||
git add src/qt/bitcoinstrings.cpp src/qt/locale/bitcoin_en.ts
|
||||
git commit
|
||||
|
||||
Syncing with Transifex
|
||||
----------------------
|
||||
|
||||
We are using http://transifex.net as a frontend for translating the client.
|
||||
We are using https://transifex.com as a frontend for translating the client.
|
||||
|
||||
https://www.transifex.net/projects/p/bitcoin/resource/tx/
|
||||
|
||||
The "transifex client":http://help.transifex.net/features/client/index.html
|
||||
will help with fetching new translations from transifex.
|
||||
https://www.transifex.com/projects/p/bitcoin/resource/tx/
|
||||
|
||||
The "Transifex client" (see: http://help.transifex.com/features/client/)
|
||||
will help with fetching new translations from Transifex. Use the following
|
||||
config to be able to connect with the client:
|
||||
|
||||
### .tx/config
|
||||
|
||||
[main]
|
||||
host = https://www.transifex.net
|
||||
host = https://www.transifex.com
|
||||
|
||||
[bitcoin.tx]
|
||||
file_filter = src/qt/locale/bitcoin_<lang>.ts
|
||||
source_file = src/qt/locale/bitcoin_en.ts
|
||||
source_lang = en
|
||||
|
||||
### .tx/config (for Windows)
|
||||
|
||||
[main]
|
||||
host = https://www.transifex.com
|
||||
|
||||
[bitcoin.tx]
|
||||
file_filter = src\qt\locale\bitcoin_<lang>.ts
|
||||
source_file = src\qt\locale\bitcoin_en.ts
|
||||
source_lang = en
|
||||
|
||||
It is also possible to directly download new translations one by one from the Transifex website.
|
||||
|
||||
### Fetching new translations
|
||||
|
||||
1. `tx pull -a`
|
||||
2. update `src/qt/bitcoin.qrc`
|
||||
2. update `src/qt/bitcoin.qrc` manually or via
|
||||
`ls src/qt/locale/*ts|xargs -n1 basename|sed 's/\(bitcoin_\(.*\)\).ts/<file alias="\2">locale/\1.qm<\/file>/'`
|
||||
3. `git add` new translations from `src/qt/locale/`
|
||||
|
||||
33
doc/unit-tests.txt
Normal file
33
doc/unit-tests.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
Compiling/running bitcoind unit tests
|
||||
------------------------------------
|
||||
|
||||
bitcoind unit tests are in the src/test/ directory; they
|
||||
use the Boost::Test unit-testing framework.
|
||||
|
||||
To compile and run the tests:
|
||||
cd src
|
||||
make -f makefile.unix test_bitcoin # Replace makefile.unix if you're not on unix
|
||||
./test_bitcoin # Runs the unit tests
|
||||
|
||||
If all tests succeed the last line of output will be:
|
||||
*** No errors detected
|
||||
|
||||
To add more tests, add BOOST_AUTO_TEST_CASE functions to the existing
|
||||
.cpp files in the test/ directory or add new .cpp files that
|
||||
implement new BOOST_AUTO_TEST_SUITE sections (the makefiles are
|
||||
set up to add test/*.cpp to test_bitcoin automatically).
|
||||
|
||||
|
||||
Compiling/running Bitcoin-Qt unit tests
|
||||
---------------------------------------
|
||||
|
||||
Bitcoin-Qt unit tests are in the src/qt/test/ directory; they
|
||||
use the Qt unit-testing framework.
|
||||
|
||||
To compile and run the tests:
|
||||
qmake bitcoin-qt.pro BITCOIN_QT_TEST=1
|
||||
make
|
||||
./bitcoin-qt_test
|
||||
|
||||
To add more tests, add them to the src/qt/test/ directory,
|
||||
the src/qt/test/test_main.cpp file, and bitcoin-qt.pro.
|
||||
35
share/genbuild.sh
Executable file
35
share/genbuild.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
FILE="$1"
|
||||
shift
|
||||
if [ -f "$FILE" ]; then
|
||||
INFO="$(head -n 1 "$FILE")"
|
||||
fi
|
||||
else
|
||||
echo "Usage: $0 <filename>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -e "$(which git)" ]; then
|
||||
# clean 'dirty' status of touched files that haven't been modified
|
||||
git diff >/dev/null 2>/dev/null
|
||||
|
||||
# get a string like "v0.6.0-66-g59887e8-dirty"
|
||||
DESC="$(git describe --dirty 2>/dev/null)"
|
||||
|
||||
# get a string like "2012-04-10 16:27:19 +0200"
|
||||
TIME="$(git log -n 1 --format="%ci")"
|
||||
fi
|
||||
|
||||
if [ -n "$DESC" ]; then
|
||||
NEWINFO="#define BUILD_DESC \"$DESC\""
|
||||
else
|
||||
NEWINFO="// No build information available"
|
||||
fi
|
||||
|
||||
# only update build.h if necessary
|
||||
if [ "$INFO" != "$NEWINFO" ]; then
|
||||
echo "$NEWINFO" >"$FILE"
|
||||
echo "#define BUILD_DATE \"$TIME\"" >>"$FILE"
|
||||
fi
|
||||
@@ -4,6 +4,8 @@ Extract _("...") strings for translation and convert to Qt4 stringdefs so that
|
||||
they can be picked up by Qt linguist.
|
||||
'''
|
||||
from subprocess import Popen, PIPE
|
||||
import glob
|
||||
import operator
|
||||
|
||||
OUT_CPP="src/qt/bitcoinstrings.cpp"
|
||||
EMPTY=['""']
|
||||
@@ -44,7 +46,7 @@ def parse_po(text):
|
||||
|
||||
return messages
|
||||
|
||||
files = ['src/base58.h', 'src/bignum.h', 'src/db.cpp', 'src/db.h', 'src/headers.h', 'src/init.cpp', 'src/init.h', 'src/irc.cpp', 'src/irc.h', 'src/key.h', 'src/main.cpp', 'src/main.h', 'src/net.cpp', 'src/net.h', 'src/noui.h', 'src/script.cpp', 'src/script.h', 'src/serialize.h', 'src/strlcpy.h', 'src/uint256.h', 'src/util.cpp', 'src/util.h']
|
||||
files = glob.glob('src/*.cpp') + glob.glob('src/*.h')
|
||||
|
||||
# xgettext -n --keyword=_ $FILES
|
||||
child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE)
|
||||
@@ -53,9 +55,16 @@ child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE)
|
||||
messages = parse_po(out)
|
||||
|
||||
f = open(OUT_CPP, 'w')
|
||||
f.write('#include <QtGlobal>\n')
|
||||
f.write('// Automatically generated by extract_strings.py\n')
|
||||
f.write('static const char *bitcoin_strings[] = {')
|
||||
f.write("""#include <QtGlobal>
|
||||
// Automatically generated by extract_strings.py
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED __attribute__((unused))
|
||||
#else
|
||||
#define UNUSED
|
||||
#endif
|
||||
""")
|
||||
f.write('static const char UNUSED *bitcoin_strings[] = {\n')
|
||||
messages.sort(key=operator.itemgetter(0))
|
||||
for (msgid, msgstr) in messages:
|
||||
if msgid != EMPTY:
|
||||
f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid)))
|
||||
@@ -5,7 +5,7 @@ SetCompressor /SOLID lzma
|
||||
|
||||
# General Symbol Definitions
|
||||
!define REGKEY "SOFTWARE\$(^Name)"
|
||||
!define VERSION 0.6.0
|
||||
!define VERSION 0.7.1
|
||||
!define COMPANY "Bitcoin project"
|
||||
!define URL http://www.bitcoin.org/
|
||||
|
||||
@@ -45,13 +45,13 @@ Var StartMenuGroup
|
||||
!insertmacro MUI_LANGUAGE English
|
||||
|
||||
# Installer attributes
|
||||
OutFile bitcoin-0.6.0-win32-setup.exe
|
||||
OutFile bitcoin-0.7.1-win32-setup.exe
|
||||
InstallDir $PROGRAMFILES\Bitcoin
|
||||
CRCCheck on
|
||||
XPStyle on
|
||||
BrandingText " "
|
||||
ShowInstDetails show
|
||||
VIProductVersion 0.6.0.0
|
||||
VIProductVersion 0.7.1.0
|
||||
VIAddVersionKey ProductName Bitcoin
|
||||
VIAddVersionKey ProductVersion "${VERSION}"
|
||||
VIAddVersionKey CompanyName "${COMPANY}"
|
||||
@@ -67,7 +67,7 @@ Section -Main SEC0000
|
||||
SetOutPath $INSTDIR
|
||||
SetOverwrite on
|
||||
File ../release/bitcoin-qt.exe
|
||||
File /oname=license.txt ../COPYING
|
||||
File /oname=COPYING.txt ../COPYING
|
||||
File /oname=readme.txt ../doc/README_windows.txt
|
||||
SetOutPath $INSTDIR\daemon
|
||||
File ../src/bitcoind.exe
|
||||
@@ -75,6 +75,10 @@ Section -Main SEC0000
|
||||
File /r /x *.exe /x *.o ../src\*.*
|
||||
SetOutPath $INSTDIR
|
||||
WriteRegStr HKCU "${REGKEY}\Components" Main 1
|
||||
|
||||
# Remove old wxwidgets-based-bitcoin executable and locales:
|
||||
Delete /REBOOTOK $INSTDIR\bitcoin.exe
|
||||
RMDir /r /REBOOTOK $INSTDIR\locale
|
||||
SectionEnd
|
||||
|
||||
Section -post SEC0001
|
||||
@@ -96,8 +100,8 @@ Section -post SEC0001
|
||||
WriteRegDWORD HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
|
||||
WriteRegStr HKCR "bitcoin" "URL Protocol" ""
|
||||
WriteRegStr HKCR "bitcoin" "" "URL:Bitcoin"
|
||||
WriteRegStr HKCR "bitcoin\DefaultIcon" "" $INSTDIR\bitcoin.exe
|
||||
WriteRegStr HKCR "bitcoin\shell\open\command" "" '"$INSTDIR\bitcoin.exe" "$$1"'
|
||||
WriteRegStr HKCR "bitcoin\DefaultIcon" "" $INSTDIR\bitcoin-qt.exe
|
||||
WriteRegStr HKCR "bitcoin\shell\open\command" "" '"$INSTDIR\bitcoin-qt.exe" "%1"'
|
||||
SectionEnd
|
||||
|
||||
# Macro for selecting uninstaller sections
|
||||
@@ -116,7 +120,7 @@ done${UNSECTION_ID}:
|
||||
# Uninstaller sections
|
||||
Section /o -un.Main UNSEC0000
|
||||
Delete /REBOOTOK $INSTDIR\bitcoin-qt.exe
|
||||
Delete /REBOOTOK $INSTDIR\license.txt
|
||||
Delete /REBOOTOK $INSTDIR\COPYING.txt
|
||||
Delete /REBOOTOK $INSTDIR\readme.txt
|
||||
RMDir /r /REBOOTOK $INSTDIR\daemon
|
||||
RMDir /r /REBOOTOK $INSTDIR\src
|
||||
|
||||
527
src/addrman.cpp
Normal file
527
src/addrman.cpp
Normal file
@@ -0,0 +1,527 @@
|
||||
// Copyright (c) 2012 Pieter Wuille
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "addrman.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int CAddrInfo::GetTriedBucket(const std::vector<unsigned char> &nKey) const
|
||||
{
|
||||
CDataStream ss1(SER_GETHASH, 0);
|
||||
std::vector<unsigned char> vchKey = GetKey();
|
||||
ss1 << nKey << vchKey;
|
||||
uint64 hash1 = Hash(ss1.begin(), ss1.end()).Get64();
|
||||
|
||||
CDataStream ss2(SER_GETHASH, 0);
|
||||
std::vector<unsigned char> vchGroupKey = GetGroup();
|
||||
ss2 << nKey << vchGroupKey << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP);
|
||||
uint64 hash2 = Hash(ss2.begin(), ss2.end()).Get64();
|
||||
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
|
||||
}
|
||||
|
||||
int CAddrInfo::GetNewBucket(const std::vector<unsigned char> &nKey, const CNetAddr& src) const
|
||||
{
|
||||
CDataStream ss1(SER_GETHASH, 0);
|
||||
std::vector<unsigned char> vchGroupKey = GetGroup();
|
||||
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup();
|
||||
ss1 << nKey << vchGroupKey << vchSourceGroupKey;
|
||||
uint64 hash1 = Hash(ss1.begin(), ss1.end()).Get64();
|
||||
|
||||
CDataStream ss2(SER_GETHASH, 0);
|
||||
ss2 << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP);
|
||||
uint64 hash2 = Hash(ss2.begin(), ss2.end()).Get64();
|
||||
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
|
||||
}
|
||||
|
||||
bool CAddrInfo::IsTerrible(int64 nNow) const
|
||||
{
|
||||
if (nLastTry && nLastTry >= nNow-60) // never remove things tried the last minute
|
||||
return false;
|
||||
|
||||
if (nTime > nNow + 10*60) // came in a flying DeLorean
|
||||
return true;
|
||||
|
||||
if (nTime==0 || nNow-nTime > ADDRMAN_HORIZON_DAYS*86400) // not seen in over a month
|
||||
return true;
|
||||
|
||||
if (nLastSuccess==0 && nAttempts>=ADDRMAN_RETRIES) // tried three times and never a success
|
||||
return true;
|
||||
|
||||
if (nNow-nLastSuccess > ADDRMAN_MIN_FAIL_DAYS*86400 && nAttempts>=ADDRMAN_MAX_FAILURES) // 10 successive failures in the last week
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
double CAddrInfo::GetChance(int64 nNow) const
|
||||
{
|
||||
double fChance = 1.0;
|
||||
|
||||
int64 nSinceLastSeen = nNow - nTime;
|
||||
int64 nSinceLastTry = nNow - nLastTry;
|
||||
|
||||
if (nSinceLastSeen < 0) nSinceLastSeen = 0;
|
||||
if (nSinceLastTry < 0) nSinceLastTry = 0;
|
||||
|
||||
fChance *= 600.0 / (600.0 + nSinceLastSeen);
|
||||
|
||||
// deprioritize very recent attempts away
|
||||
if (nSinceLastTry < 60*10)
|
||||
fChance *= 0.01;
|
||||
|
||||
// deprioritize 50% after each failed attempt
|
||||
for (int n=0; n<nAttempts; n++)
|
||||
fChance /= 1.5;
|
||||
|
||||
return fChance;
|
||||
}
|
||||
|
||||
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int *pnId)
|
||||
{
|
||||
std::map<CNetAddr, int>::iterator it = mapAddr.find(addr);
|
||||
if (it == mapAddr.end())
|
||||
return NULL;
|
||||
if (pnId)
|
||||
*pnId = (*it).second;
|
||||
std::map<int, CAddrInfo>::iterator it2 = mapInfo.find((*it).second);
|
||||
if (it2 != mapInfo.end())
|
||||
return &(*it2).second;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CAddrInfo* CAddrMan::Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId)
|
||||
{
|
||||
int nId = nIdCount++;
|
||||
mapInfo[nId] = CAddrInfo(addr, addrSource);
|
||||
mapAddr[addr] = nId;
|
||||
mapInfo[nId].nRandomPos = vRandom.size();
|
||||
vRandom.push_back(nId);
|
||||
if (pnId)
|
||||
*pnId = nId;
|
||||
return &mapInfo[nId];
|
||||
}
|
||||
|
||||
void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
|
||||
{
|
||||
if (nRndPos1 == nRndPos2)
|
||||
return;
|
||||
|
||||
assert(nRndPos1 < vRandom.size() && nRndPos2 < vRandom.size());
|
||||
|
||||
int nId1 = vRandom[nRndPos1];
|
||||
int nId2 = vRandom[nRndPos2];
|
||||
|
||||
assert(mapInfo.count(nId1) == 1);
|
||||
assert(mapInfo.count(nId2) == 1);
|
||||
|
||||
mapInfo[nId1].nRandomPos = nRndPos2;
|
||||
mapInfo[nId2].nRandomPos = nRndPos1;
|
||||
|
||||
vRandom[nRndPos1] = nId2;
|
||||
vRandom[nRndPos2] = nId1;
|
||||
}
|
||||
|
||||
int CAddrMan::SelectTried(int nKBucket)
|
||||
{
|
||||
std::vector<int> &vTried = vvTried[nKBucket];
|
||||
|
||||
// random shuffle the first few elements (using the entire list)
|
||||
// find the least recently tried among them
|
||||
int64 nOldest = -1;
|
||||
int nOldestPos = -1;
|
||||
for (unsigned int i = 0; i < ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT && i < vTried.size(); i++)
|
||||
{
|
||||
int nPos = GetRandInt(vTried.size() - i) + i;
|
||||
int nTemp = vTried[nPos];
|
||||
vTried[nPos] = vTried[i];
|
||||
vTried[i] = nTemp;
|
||||
assert(nOldest == -1 || mapInfo.count(nTemp) == 1);
|
||||
if (nOldest == -1 || mapInfo[nTemp].nLastSuccess < mapInfo[nOldest].nLastSuccess) {
|
||||
nOldest = nTemp;
|
||||
nOldestPos = nPos;
|
||||
}
|
||||
}
|
||||
|
||||
return nOldestPos;
|
||||
}
|
||||
|
||||
int CAddrMan::ShrinkNew(int nUBucket)
|
||||
{
|
||||
assert(nUBucket >= 0 && (unsigned int)nUBucket < vvNew.size());
|
||||
std::set<int> &vNew = vvNew[nUBucket];
|
||||
|
||||
// first look for deletable items
|
||||
for (std::set<int>::iterator it = vNew.begin(); it != vNew.end(); it++)
|
||||
{
|
||||
assert(mapInfo.count(*it));
|
||||
CAddrInfo &info = mapInfo[*it];
|
||||
if (info.IsTerrible())
|
||||
{
|
||||
if (--info.nRefCount == 0)
|
||||
{
|
||||
SwapRandom(info.nRandomPos, vRandom.size()-1);
|
||||
vRandom.pop_back();
|
||||
mapAddr.erase(info);
|
||||
mapInfo.erase(*it);
|
||||
nNew--;
|
||||
}
|
||||
vNew.erase(it);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, select four randomly, and pick the oldest of those to replace
|
||||
int n[4] = {GetRandInt(vNew.size()), GetRandInt(vNew.size()), GetRandInt(vNew.size()), GetRandInt(vNew.size())};
|
||||
int nI = 0;
|
||||
int nOldest = -1;
|
||||
for (std::set<int>::iterator it = vNew.begin(); it != vNew.end(); it++)
|
||||
{
|
||||
if (nI == n[0] || nI == n[1] || nI == n[2] || nI == n[3])
|
||||
{
|
||||
assert(nOldest == -1 || mapInfo.count(*it) == 1);
|
||||
if (nOldest == -1 || mapInfo[*it].nTime < mapInfo[nOldest].nTime)
|
||||
nOldest = *it;
|
||||
}
|
||||
nI++;
|
||||
}
|
||||
assert(mapInfo.count(nOldest) == 1);
|
||||
CAddrInfo &info = mapInfo[nOldest];
|
||||
if (--info.nRefCount == 0)
|
||||
{
|
||||
SwapRandom(info.nRandomPos, vRandom.size()-1);
|
||||
vRandom.pop_back();
|
||||
mapAddr.erase(info);
|
||||
mapInfo.erase(nOldest);
|
||||
nNew--;
|
||||
}
|
||||
vNew.erase(nOldest);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CAddrMan::MakeTried(CAddrInfo& info, int nId, int nOrigin)
|
||||
{
|
||||
assert(vvNew[nOrigin].count(nId) == 1);
|
||||
|
||||
// remove the entry from all new buckets
|
||||
for (std::vector<std::set<int> >::iterator it = vvNew.begin(); it != vvNew.end(); it++)
|
||||
{
|
||||
if ((*it).erase(nId))
|
||||
info.nRefCount--;
|
||||
}
|
||||
nNew--;
|
||||
|
||||
assert(info.nRefCount == 0);
|
||||
|
||||
// what tried bucket to move the entry to
|
||||
int nKBucket = info.GetTriedBucket(nKey);
|
||||
std::vector<int> &vTried = vvTried[nKBucket];
|
||||
|
||||
// first check whether there is place to just add it
|
||||
if (vTried.size() < ADDRMAN_TRIED_BUCKET_SIZE)
|
||||
{
|
||||
vTried.push_back(nId);
|
||||
nTried++;
|
||||
info.fInTried = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise, find an item to evict
|
||||
int nPos = SelectTried(nKBucket);
|
||||
|
||||
// find which new bucket it belongs to
|
||||
assert(mapInfo.count(vTried[nPos]) == 1);
|
||||
int nUBucket = mapInfo[vTried[nPos]].GetNewBucket(nKey);
|
||||
std::set<int> &vNew = vvNew[nUBucket];
|
||||
|
||||
// remove the to-be-replaced tried entry from the tried set
|
||||
CAddrInfo& infoOld = mapInfo[vTried[nPos]];
|
||||
infoOld.fInTried = false;
|
||||
infoOld.nRefCount = 1;
|
||||
// do not update nTried, as we are going to move something else there immediately
|
||||
|
||||
// check whether there is place in that one,
|
||||
if (vNew.size() < ADDRMAN_NEW_BUCKET_SIZE)
|
||||
{
|
||||
// if so, move it back there
|
||||
vNew.insert(vTried[nPos]);
|
||||
} else {
|
||||
// otherwise, move it to the new bucket nId came from (there is certainly place there)
|
||||
vvNew[nOrigin].insert(vTried[nPos]);
|
||||
}
|
||||
nNew++;
|
||||
|
||||
vTried[nPos] = nId;
|
||||
// we just overwrote an entry in vTried; no need to update nTried
|
||||
info.fInTried = true;
|
||||
return;
|
||||
}
|
||||
|
||||
void CAddrMan::Good_(const CService &addr, int64 nTime)
|
||||
{
|
||||
// printf("Good: addr=%s\n", addr.ToString().c_str());
|
||||
|
||||
int nId;
|
||||
CAddrInfo *pinfo = Find(addr, &nId);
|
||||
|
||||
// if not found, bail out
|
||||
if (!pinfo)
|
||||
return;
|
||||
|
||||
CAddrInfo &info = *pinfo;
|
||||
|
||||
// check whether we are talking about the exact same CService (including same port)
|
||||
if (info != addr)
|
||||
return;
|
||||
|
||||
// update info
|
||||
info.nLastSuccess = nTime;
|
||||
info.nLastTry = nTime;
|
||||
info.nTime = nTime;
|
||||
info.nAttempts = 0;
|
||||
|
||||
// if it is already in the tried set, don't do anything else
|
||||
if (info.fInTried)
|
||||
return;
|
||||
|
||||
// find a bucket it is in now
|
||||
int nRnd = GetRandInt(vvNew.size());
|
||||
int nUBucket = -1;
|
||||
for (unsigned int n = 0; n < vvNew.size(); n++)
|
||||
{
|
||||
int nB = (n+nRnd) % vvNew.size();
|
||||
std::set<int> &vNew = vvNew[nB];
|
||||
if (vNew.count(nId))
|
||||
{
|
||||
nUBucket = nB;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if no bucket is found, something bad happened;
|
||||
// TODO: maybe re-add the node, but for now, just bail out
|
||||
if (nUBucket == -1) return;
|
||||
|
||||
printf("Moving %s to tried\n", addr.ToString().c_str());
|
||||
|
||||
// move nId to the tried tables
|
||||
MakeTried(info, nId, nUBucket);
|
||||
}
|
||||
|
||||
bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePenalty)
|
||||
{
|
||||
if (!addr.IsRoutable())
|
||||
return false;
|
||||
|
||||
bool fNew = false;
|
||||
int nId;
|
||||
CAddrInfo *pinfo = Find(addr, &nId);
|
||||
|
||||
if (pinfo)
|
||||
{
|
||||
// periodically update nTime
|
||||
bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
|
||||
int64 nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
|
||||
if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty))
|
||||
pinfo->nTime = max((int64)0, addr.nTime - nTimePenalty);
|
||||
|
||||
// add services
|
||||
pinfo->nServices |= addr.nServices;
|
||||
|
||||
// do not update if no new information is present
|
||||
if (!addr.nTime || (pinfo->nTime && addr.nTime <= pinfo->nTime))
|
||||
return false;
|
||||
|
||||
// do not update if the entry was already in the "tried" table
|
||||
if (pinfo->fInTried)
|
||||
return false;
|
||||
|
||||
// do not update if the max reference count is reached
|
||||
if (pinfo->nRefCount == ADDRMAN_NEW_BUCKETS_PER_ADDRESS)
|
||||
return false;
|
||||
|
||||
// stochastic test: previous nRefCount == N: 2^N times harder to increase it
|
||||
int nFactor = 1;
|
||||
for (int n=0; n<pinfo->nRefCount; n++)
|
||||
nFactor *= 2;
|
||||
if (nFactor > 1 && (GetRandInt(nFactor) != 0))
|
||||
return false;
|
||||
} else {
|
||||
pinfo = Create(addr, source, &nId);
|
||||
pinfo->nTime = max((int64)0, (int64)pinfo->nTime - nTimePenalty);
|
||||
// printf("Added %s [nTime=%fhr]\n", pinfo->ToString().c_str(), (GetAdjustedTime() - pinfo->nTime) / 3600.0);
|
||||
nNew++;
|
||||
fNew = true;
|
||||
}
|
||||
|
||||
int nUBucket = pinfo->GetNewBucket(nKey, source);
|
||||
std::set<int> &vNew = vvNew[nUBucket];
|
||||
if (!vNew.count(nId))
|
||||
{
|
||||
pinfo->nRefCount++;
|
||||
if (vNew.size() == ADDRMAN_NEW_BUCKET_SIZE)
|
||||
ShrinkNew(nUBucket);
|
||||
vvNew[nUBucket].insert(nId);
|
||||
}
|
||||
return fNew;
|
||||
}
|
||||
|
||||
void CAddrMan::Attempt_(const CService &addr, int64 nTime)
|
||||
{
|
||||
CAddrInfo *pinfo = Find(addr);
|
||||
|
||||
// if not found, bail out
|
||||
if (!pinfo)
|
||||
return;
|
||||
|
||||
CAddrInfo &info = *pinfo;
|
||||
|
||||
// check whether we are talking about the exact same CService (including same port)
|
||||
if (info != addr)
|
||||
return;
|
||||
|
||||
// update info
|
||||
info.nLastTry = nTime;
|
||||
info.nAttempts++;
|
||||
}
|
||||
|
||||
CAddress CAddrMan::Select_(int nUnkBias)
|
||||
{
|
||||
if (size() == 0)
|
||||
return CAddress();
|
||||
|
||||
double nCorTried = sqrt(nTried) * (100.0 - nUnkBias);
|
||||
double nCorNew = sqrt(nNew) * nUnkBias;
|
||||
if ((nCorTried + nCorNew)*GetRandInt(1<<30)/(1<<30) < nCorTried)
|
||||
{
|
||||
// use a tried node
|
||||
double fChanceFactor = 1.0;
|
||||
while(1)
|
||||
{
|
||||
int nKBucket = GetRandInt(vvTried.size());
|
||||
std::vector<int> &vTried = vvTried[nKBucket];
|
||||
if (vTried.size() == 0) continue;
|
||||
int nPos = GetRandInt(vTried.size());
|
||||
assert(mapInfo.count(vTried[nPos]) == 1);
|
||||
CAddrInfo &info = mapInfo[vTried[nPos]];
|
||||
if (GetRandInt(1<<30) < fChanceFactor*info.GetChance()*(1<<30))
|
||||
return info;
|
||||
fChanceFactor *= 1.2;
|
||||
}
|
||||
} else {
|
||||
// use a new node
|
||||
double fChanceFactor = 1.0;
|
||||
while(1)
|
||||
{
|
||||
int nUBucket = GetRandInt(vvNew.size());
|
||||
std::set<int> &vNew = vvNew[nUBucket];
|
||||
if (vNew.size() == 0) continue;
|
||||
int nPos = GetRandInt(vNew.size());
|
||||
std::set<int>::iterator it = vNew.begin();
|
||||
while (nPos--)
|
||||
it++;
|
||||
assert(mapInfo.count(*it) == 1);
|
||||
CAddrInfo &info = mapInfo[*it];
|
||||
if (GetRandInt(1<<30) < fChanceFactor*info.GetChance()*(1<<30))
|
||||
return info;
|
||||
fChanceFactor *= 1.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ADDRMAN
|
||||
int CAddrMan::Check_()
|
||||
{
|
||||
std::set<int> setTried;
|
||||
std::map<int, int> mapNew;
|
||||
|
||||
if (vRandom.size() != nTried + nNew) return -7;
|
||||
|
||||
for (std::map<int, CAddrInfo>::iterator it = mapInfo.begin(); it != mapInfo.end(); it++)
|
||||
{
|
||||
int n = (*it).first;
|
||||
CAddrInfo &info = (*it).second;
|
||||
if (info.fInTried)
|
||||
{
|
||||
|
||||
if (!info.nLastSuccess) return -1;
|
||||
if (info.nRefCount) return -2;
|
||||
setTried.insert(n);
|
||||
} else {
|
||||
if (info.nRefCount < 0 || info.nRefCount > ADDRMAN_NEW_BUCKETS_PER_ADDRESS) return -3;
|
||||
if (!info.nRefCount) return -4;
|
||||
mapNew[n] = info.nRefCount;
|
||||
}
|
||||
if (mapAddr[info] != n) return -5;
|
||||
if (info.nRandomPos<0 || info.nRandomPos>=vRandom.size() || vRandom[info.nRandomPos] != n) return -14;
|
||||
if (info.nLastTry < 0) return -6;
|
||||
if (info.nLastSuccess < 0) return -8;
|
||||
}
|
||||
|
||||
if (setTried.size() != nTried) return -9;
|
||||
if (mapNew.size() != nNew) return -10;
|
||||
|
||||
for (int n=0; n<vvTried.size(); n++)
|
||||
{
|
||||
std::vector<int> &vTried = vvTried[n];
|
||||
for (std::vector<int>::iterator it = vTried.begin(); it != vTried.end(); it++)
|
||||
{
|
||||
if (!setTried.count(*it)) return -11;
|
||||
setTried.erase(*it);
|
||||
}
|
||||
}
|
||||
|
||||
for (int n=0; n<vvNew.size(); n++)
|
||||
{
|
||||
std::set<int> &vNew = vvNew[n];
|
||||
for (std::set<int>::iterator it = vNew.begin(); it != vNew.end(); it++)
|
||||
{
|
||||
if (!mapNew.count(*it)) return -12;
|
||||
if (--mapNew[*it] == 0)
|
||||
mapNew.erase(*it);
|
||||
}
|
||||
}
|
||||
|
||||
if (setTried.size()) return -13;
|
||||
if (mapNew.size()) return -15;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CAddrMan::GetAddr_(std::vector<CAddress> &vAddr)
|
||||
{
|
||||
int nNodes = ADDRMAN_GETADDR_MAX_PCT*vRandom.size()/100;
|
||||
if (nNodes > ADDRMAN_GETADDR_MAX)
|
||||
nNodes = ADDRMAN_GETADDR_MAX;
|
||||
|
||||
// perform a random shuffle over the first nNodes elements of vRandom (selecting from all)
|
||||
for (int n = 0; n<nNodes; n++)
|
||||
{
|
||||
int nRndPos = GetRandInt(vRandom.size() - n) + n;
|
||||
SwapRandom(n, nRndPos);
|
||||
assert(mapInfo.count(vRandom[n]) == 1);
|
||||
vAddr.push_back(mapInfo[vRandom[n]]);
|
||||
}
|
||||
}
|
||||
|
||||
void CAddrMan::Connected_(const CService &addr, int64 nTime)
|
||||
{
|
||||
CAddrInfo *pinfo = Find(addr);
|
||||
|
||||
// if not found, bail out
|
||||
if (!pinfo)
|
||||
return;
|
||||
|
||||
CAddrInfo &info = *pinfo;
|
||||
|
||||
// check whether we are talking about the exact same CService (including same port)
|
||||
if (info != addr)
|
||||
return;
|
||||
|
||||
// update info
|
||||
int64 nUpdateInterval = 20 * 60;
|
||||
if (nTime - info.nTime > nUpdateInterval)
|
||||
info.nTime = nTime;
|
||||
}
|
||||
503
src/addrman.h
Normal file
503
src/addrman.h
Normal file
@@ -0,0 +1,503 @@
|
||||
// Copyright (c) 2012 Pieter Wuille
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef _BITCOIN_ADDRMAN
|
||||
#define _BITCOIN_ADDRMAN 1
|
||||
|
||||
#include "netbase.h"
|
||||
#include "protocol.h"
|
||||
#include "util.h"
|
||||
#include "sync.h"
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
|
||||
/** Extended statistics about a CAddress */
|
||||
class CAddrInfo : public CAddress
|
||||
{
|
||||
private:
|
||||
// where knowledge about this address first came from
|
||||
CNetAddr source;
|
||||
|
||||
// last successful connection by us
|
||||
int64 nLastSuccess;
|
||||
|
||||
// last try whatsoever by us:
|
||||
// int64 CAddress::nLastTry
|
||||
|
||||
// connection attempts since last successful attempt
|
||||
int nAttempts;
|
||||
|
||||
// reference count in new sets (memory only)
|
||||
int nRefCount;
|
||||
|
||||
// in tried set? (memory only)
|
||||
bool fInTried;
|
||||
|
||||
// position in vRandom
|
||||
int nRandomPos;
|
||||
|
||||
friend class CAddrMan;
|
||||
|
||||
public:
|
||||
|
||||
IMPLEMENT_SERIALIZE(
|
||||
CAddress* pthis = (CAddress*)(this);
|
||||
READWRITE(*pthis);
|
||||
READWRITE(source);
|
||||
READWRITE(nLastSuccess);
|
||||
READWRITE(nAttempts);
|
||||
)
|
||||
|
||||
void Init()
|
||||
{
|
||||
nLastSuccess = 0;
|
||||
nLastTry = 0;
|
||||
nAttempts = 0;
|
||||
nRefCount = 0;
|
||||
fInTried = false;
|
||||
nRandomPos = -1;
|
||||
}
|
||||
|
||||
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
CAddrInfo() : CAddress(), source()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// Calculate in which "tried" bucket this entry belongs
|
||||
int GetTriedBucket(const std::vector<unsigned char> &nKey) const;
|
||||
|
||||
// Calculate in which "new" bucket this entry belongs, given a certain source
|
||||
int GetNewBucket(const std::vector<unsigned char> &nKey, const CNetAddr& src) const;
|
||||
|
||||
// Calculate in which "new" bucket this entry belongs, using its default source
|
||||
int GetNewBucket(const std::vector<unsigned char> &nKey) const
|
||||
{
|
||||
return GetNewBucket(nKey, source);
|
||||
}
|
||||
|
||||
// Determine whether the statistics about this entry are bad enough so that it can just be deleted
|
||||
bool IsTerrible(int64 nNow = GetAdjustedTime()) const;
|
||||
|
||||
// Calculate the relative chance this entry should be given when selecting nodes to connect to
|
||||
double GetChance(int64 nNow = GetAdjustedTime()) const;
|
||||
|
||||
};
|
||||
|
||||
// Stochastic address manager
|
||||
//
|
||||
// Design goals:
|
||||
// * Only keep a limited number of addresses around, so that addr.dat and memory requirements do not grow without bound.
|
||||
// * Keep the address tables in-memory, and asynchronously dump the entire to able in addr.dat.
|
||||
// * Make sure no (localized) attacker can fill the entire table with his nodes/addresses.
|
||||
//
|
||||
// To that end:
|
||||
// * Addresses are organized into buckets.
|
||||
// * Address that have not yet been tried go into 256 "new" buckets.
|
||||
// * Based on the address range (/16 for IPv4) of source of the information, 32 buckets are selected at random
|
||||
// * The actual bucket is chosen from one of these, based on the range the address itself is located.
|
||||
// * One single address can occur in up to 4 different buckets, to increase selection chances for addresses that
|
||||
// are seen frequently. The chance for increasing this multiplicity decreases exponentially.
|
||||
// * When adding a new address to a full bucket, a randomly chosen entry (with a bias favoring less recently seen
|
||||
// ones) is removed from it first.
|
||||
// * Addresses of nodes that are known to be accessible go into 64 "tried" buckets.
|
||||
// * Each address range selects at random 4 of these buckets.
|
||||
// * The actual bucket is chosen from one of these, based on the full address.
|
||||
// * When adding a new good address to a full bucket, a randomly chosen entry (with a bias favoring less recently
|
||||
// tried ones) is evicted from it, back to the "new" buckets.
|
||||
// * Bucket selection is based on cryptographic hashing, using a randomly-generated 256-bit key, which should not
|
||||
// be observable by adversaries.
|
||||
// * Several indexes are kept for high performance. Defining DEBUG_ADDRMAN will introduce frequent (and expensive)
|
||||
// consistency checks for the entire data structure.
|
||||
|
||||
// total number of buckets for tried addresses
|
||||
#define ADDRMAN_TRIED_BUCKET_COUNT 64
|
||||
|
||||
// maximum allowed number of entries in buckets for tried addresses
|
||||
#define ADDRMAN_TRIED_BUCKET_SIZE 64
|
||||
|
||||
// total number of buckets for new addresses
|
||||
#define ADDRMAN_NEW_BUCKET_COUNT 256
|
||||
|
||||
// maximum allowed number of entries in buckets for new addresses
|
||||
#define ADDRMAN_NEW_BUCKET_SIZE 64
|
||||
|
||||
// over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread
|
||||
#define ADDRMAN_TRIED_BUCKETS_PER_GROUP 4
|
||||
|
||||
// over how many buckets entries with new addresses originating from a single group are spread
|
||||
#define ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP 32
|
||||
|
||||
// in how many buckets for entries with new addresses a single address may occur
|
||||
#define ADDRMAN_NEW_BUCKETS_PER_ADDRESS 4
|
||||
|
||||
// how many entries in a bucket with tried addresses are inspected, when selecting one to replace
|
||||
#define ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT 4
|
||||
|
||||
// how old addresses can maximally be
|
||||
#define ADDRMAN_HORIZON_DAYS 30
|
||||
|
||||
// after how many failed attempts we give up on a new node
|
||||
#define ADDRMAN_RETRIES 3
|
||||
|
||||
// how many successive failures are allowed ...
|
||||
#define ADDRMAN_MAX_FAILURES 10
|
||||
|
||||
// ... in at least this many days
|
||||
#define ADDRMAN_MIN_FAIL_DAYS 7
|
||||
|
||||
// the maximum percentage of nodes to return in a getaddr call
|
||||
#define ADDRMAN_GETADDR_MAX_PCT 23
|
||||
|
||||
// the maximum number of nodes to return in a getaddr call
|
||||
#define ADDRMAN_GETADDR_MAX 2500
|
||||
|
||||
/** Stochastical (IP) address manager */
|
||||
class CAddrMan
|
||||
{
|
||||
private:
|
||||
// critical section to protect the inner data structures
|
||||
mutable CCriticalSection cs;
|
||||
|
||||
// secret key to randomize bucket select with
|
||||
std::vector<unsigned char> nKey;
|
||||
|
||||
// last used nId
|
||||
int nIdCount;
|
||||
|
||||
// table with information about all nIds
|
||||
std::map<int, CAddrInfo> mapInfo;
|
||||
|
||||
// find an nId based on its network address
|
||||
std::map<CNetAddr, int> mapAddr;
|
||||
|
||||
// randomly-ordered vector of all nIds
|
||||
std::vector<int> vRandom;
|
||||
|
||||
// number of "tried" entries
|
||||
int nTried;
|
||||
|
||||
// list of "tried" buckets
|
||||
std::vector<std::vector<int> > vvTried;
|
||||
|
||||
// number of (unique) "new" entries
|
||||
int nNew;
|
||||
|
||||
// list of "new" buckets
|
||||
std::vector<std::set<int> > vvNew;
|
||||
|
||||
protected:
|
||||
|
||||
// Find an entry.
|
||||
CAddrInfo* Find(const CNetAddr& addr, int *pnId = NULL);
|
||||
|
||||
// find an entry, creating it if necessary.
|
||||
// nTime and nServices of found node is updated, if necessary.
|
||||
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);
|
||||
|
||||
// Swap two elements in vRandom.
|
||||
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2);
|
||||
|
||||
// Return position in given bucket to replace.
|
||||
int SelectTried(int nKBucket);
|
||||
|
||||
// Remove an element from a "new" bucket.
|
||||
// This is the only place where actual deletes occur.
|
||||
// They are never deleted while in the "tried" table, only possibly evicted back to the "new" table.
|
||||
int ShrinkNew(int nUBucket);
|
||||
|
||||
// Move an entry from the "new" table(s) to the "tried" table
|
||||
// @pre vvUnkown[nOrigin].count(nId) != 0
|
||||
void MakeTried(CAddrInfo& info, int nId, int nOrigin);
|
||||
|
||||
// Mark an entry "good", possibly moving it from "new" to "tried".
|
||||
void Good_(const CService &addr, int64 nTime);
|
||||
|
||||
// Add an entry to the "new" table.
|
||||
bool Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePenalty);
|
||||
|
||||
// Mark an entry as attempted to connect.
|
||||
void Attempt_(const CService &addr, int64 nTime);
|
||||
|
||||
// Select an address to connect to.
|
||||
// nUnkBias determines how much to favor new addresses over tried ones (min=0, max=100)
|
||||
CAddress Select_(int nUnkBias);
|
||||
|
||||
#ifdef DEBUG_ADDRMAN
|
||||
// Perform consistency check. Returns an error code or zero.
|
||||
int Check_();
|
||||
#endif
|
||||
|
||||
// Select several addresses at once.
|
||||
void GetAddr_(std::vector<CAddress> &vAddr);
|
||||
|
||||
// Mark an entry as currently-connected-to.
|
||||
void Connected_(const CService &addr, int64 nTime);
|
||||
|
||||
public:
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(({
|
||||
// serialized format:
|
||||
// * version byte (currently 0)
|
||||
// * nKey
|
||||
// * nNew
|
||||
// * nTried
|
||||
// * number of "new" buckets
|
||||
// * all nNew addrinfos in vvNew
|
||||
// * all nTried addrinfos in vvTried
|
||||
// * for each bucket:
|
||||
// * number of elements
|
||||
// * for each element: index
|
||||
//
|
||||
// Notice that vvTried, mapAddr and vVector are never encoded explicitly;
|
||||
// they are instead reconstructed from the other information.
|
||||
//
|
||||
// vvNew is serialized, but only used if ADDRMAN_UNKOWN_BUCKET_COUNT didn't change,
|
||||
// otherwise it is reconstructed as well.
|
||||
//
|
||||
// This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
|
||||
// changes to the ADDRMAN_ parameters without breaking the on-disk structure.
|
||||
{
|
||||
LOCK(cs);
|
||||
unsigned char nVersion = 0;
|
||||
READWRITE(nVersion);
|
||||
READWRITE(nKey);
|
||||
READWRITE(nNew);
|
||||
READWRITE(nTried);
|
||||
|
||||
CAddrMan *am = const_cast<CAddrMan*>(this);
|
||||
if (fWrite)
|
||||
{
|
||||
int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT;
|
||||
READWRITE(nUBuckets);
|
||||
std::map<int, int> mapUnkIds;
|
||||
int nIds = 0;
|
||||
for (std::map<int, CAddrInfo>::iterator it = am->mapInfo.begin(); it != am->mapInfo.end(); it++)
|
||||
{
|
||||
if (nIds == nNew) break; // this means nNew was wrong, oh ow
|
||||
mapUnkIds[(*it).first] = nIds;
|
||||
CAddrInfo &info = (*it).second;
|
||||
if (info.nRefCount)
|
||||
{
|
||||
READWRITE(info);
|
||||
nIds++;
|
||||
}
|
||||
}
|
||||
nIds = 0;
|
||||
for (std::map<int, CAddrInfo>::iterator it = am->mapInfo.begin(); it != am->mapInfo.end(); it++)
|
||||
{
|
||||
if (nIds == nTried) break; // this means nTried was wrong, oh ow
|
||||
CAddrInfo &info = (*it).second;
|
||||
if (info.fInTried)
|
||||
{
|
||||
READWRITE(info);
|
||||
nIds++;
|
||||
}
|
||||
}
|
||||
for (std::vector<std::set<int> >::iterator it = am->vvNew.begin(); it != am->vvNew.end(); it++)
|
||||
{
|
||||
const std::set<int> &vNew = (*it);
|
||||
int nSize = vNew.size();
|
||||
READWRITE(nSize);
|
||||
for (std::set<int>::iterator it2 = vNew.begin(); it2 != vNew.end(); it2++)
|
||||
{
|
||||
int nIndex = mapUnkIds[*it2];
|
||||
READWRITE(nIndex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int nUBuckets = 0;
|
||||
READWRITE(nUBuckets);
|
||||
am->nIdCount = 0;
|
||||
am->mapInfo.clear();
|
||||
am->mapAddr.clear();
|
||||
am->vRandom.clear();
|
||||
am->vvTried = std::vector<std::vector<int> >(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0));
|
||||
am->vvNew = std::vector<std::set<int> >(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>());
|
||||
for (int n = 0; n < am->nNew; n++)
|
||||
{
|
||||
CAddrInfo &info = am->mapInfo[n];
|
||||
READWRITE(info);
|
||||
am->mapAddr[info] = n;
|
||||
info.nRandomPos = vRandom.size();
|
||||
am->vRandom.push_back(n);
|
||||
if (nUBuckets != ADDRMAN_NEW_BUCKET_COUNT)
|
||||
{
|
||||
am->vvNew[info.GetNewBucket(am->nKey)].insert(n);
|
||||
info.nRefCount++;
|
||||
}
|
||||
}
|
||||
am->nIdCount = am->nNew;
|
||||
int nLost = 0;
|
||||
for (int n = 0; n < am->nTried; n++)
|
||||
{
|
||||
CAddrInfo info;
|
||||
READWRITE(info);
|
||||
std::vector<int> &vTried = am->vvTried[info.GetTriedBucket(am->nKey)];
|
||||
if (vTried.size() < ADDRMAN_TRIED_BUCKET_SIZE)
|
||||
{
|
||||
info.nRandomPos = vRandom.size();
|
||||
info.fInTried = true;
|
||||
am->vRandom.push_back(am->nIdCount);
|
||||
am->mapInfo[am->nIdCount] = info;
|
||||
am->mapAddr[info] = am->nIdCount;
|
||||
vTried.push_back(am->nIdCount);
|
||||
am->nIdCount++;
|
||||
} else {
|
||||
nLost++;
|
||||
}
|
||||
}
|
||||
am->nTried -= nLost;
|
||||
for (int b = 0; b < nUBuckets; b++)
|
||||
{
|
||||
std::set<int> &vNew = am->vvNew[b];
|
||||
int nSize = 0;
|
||||
READWRITE(nSize);
|
||||
for (int n = 0; n < nSize; n++)
|
||||
{
|
||||
int nIndex = 0;
|
||||
READWRITE(nIndex);
|
||||
CAddrInfo &info = am->mapInfo[nIndex];
|
||||
if (nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS)
|
||||
{
|
||||
info.nRefCount++;
|
||||
vNew.insert(nIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});)
|
||||
|
||||
CAddrMan() : vRandom(0), vvTried(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0)), vvNew(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>())
|
||||
{
|
||||
nKey.resize(32);
|
||||
RAND_bytes(&nKey[0], 32);
|
||||
|
||||
nIdCount = 0;
|
||||
nTried = 0;
|
||||
nNew = 0;
|
||||
}
|
||||
|
||||
// Return the number of (unique) addresses in all tables.
|
||||
int size()
|
||||
{
|
||||
return vRandom.size();
|
||||
}
|
||||
|
||||
// Consistency check
|
||||
void Check()
|
||||
{
|
||||
#ifdef DEBUG_ADDRMAN
|
||||
{
|
||||
LOCK(cs);
|
||||
int err;
|
||||
if ((err=Check_()))
|
||||
printf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Add a single address.
|
||||
bool Add(const CAddress &addr, const CNetAddr& source, int64 nTimePenalty = 0)
|
||||
{
|
||||
bool fRet = false;
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
fRet |= Add_(addr, source, nTimePenalty);
|
||||
Check();
|
||||
}
|
||||
if (fRet)
|
||||
printf("Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
|
||||
return fRet;
|
||||
}
|
||||
|
||||
// Add multiple addresses.
|
||||
bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64 nTimePenalty = 0)
|
||||
{
|
||||
int nAdd = 0;
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
|
||||
nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
|
||||
Check();
|
||||
}
|
||||
if (nAdd)
|
||||
printf("Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
|
||||
return nAdd > 0;
|
||||
}
|
||||
|
||||
// Mark an entry as accessible.
|
||||
void Good(const CService &addr, int64 nTime = GetAdjustedTime())
|
||||
{
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
Good_(addr, nTime);
|
||||
Check();
|
||||
}
|
||||
}
|
||||
|
||||
// Mark an entry as connection attempted to.
|
||||
void Attempt(const CService &addr, int64 nTime = GetAdjustedTime())
|
||||
{
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
Attempt_(addr, nTime);
|
||||
Check();
|
||||
}
|
||||
}
|
||||
|
||||
// Choose an address to connect to.
|
||||
// nUnkBias determines how much "new" entries are favored over "tried" ones (0-100).
|
||||
CAddress Select(int nUnkBias = 50)
|
||||
{
|
||||
CAddress addrRet;
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
addrRet = Select_(nUnkBias);
|
||||
Check();
|
||||
}
|
||||
return addrRet;
|
||||
}
|
||||
|
||||
// Return a bunch of addresses, selected at random.
|
||||
std::vector<CAddress> GetAddr()
|
||||
{
|
||||
Check();
|
||||
std::vector<CAddress> vAddr;
|
||||
{
|
||||
LOCK(cs);
|
||||
GetAddr_(vAddr);
|
||||
}
|
||||
Check();
|
||||
return vAddr;
|
||||
}
|
||||
|
||||
// Mark an entry as currently-connected-to.
|
||||
void Connected(const CService &addr, int64 nTime = GetAdjustedTime())
|
||||
{
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
Connected_(addr, nTime);
|
||||
Check();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
239
src/alert.cpp
Normal file
239
src/alert.cpp
Normal file
@@ -0,0 +1,239 @@
|
||||
//
|
||||
// Alert system
|
||||
//
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <map>
|
||||
|
||||
#include "alert.h"
|
||||
#include "key.h"
|
||||
#include "net.h"
|
||||
#include "sync.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
map<uint256, CAlert> mapAlerts;
|
||||
CCriticalSection cs_mapAlerts;
|
||||
|
||||
static const char* pszMainKey = "04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284";
|
||||
static const char* pszTestKey = "04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a";
|
||||
|
||||
void CUnsignedAlert::SetNull()
|
||||
{
|
||||
nVersion = 1;
|
||||
nRelayUntil = 0;
|
||||
nExpiration = 0;
|
||||
nID = 0;
|
||||
nCancel = 0;
|
||||
setCancel.clear();
|
||||
nMinVer = 0;
|
||||
nMaxVer = 0;
|
||||
setSubVer.clear();
|
||||
nPriority = 0;
|
||||
|
||||
strComment.clear();
|
||||
strStatusBar.clear();
|
||||
strReserved.clear();
|
||||
}
|
||||
|
||||
std::string CUnsignedAlert::ToString() const
|
||||
{
|
||||
std::string strSetCancel;
|
||||
BOOST_FOREACH(int n, setCancel)
|
||||
strSetCancel += strprintf("%d ", n);
|
||||
std::string strSetSubVer;
|
||||
BOOST_FOREACH(std::string str, setSubVer)
|
||||
strSetSubVer += "\"" + str + "\" ";
|
||||
return strprintf(
|
||||
"CAlert(\n"
|
||||
" nVersion = %d\n"
|
||||
" nRelayUntil = %"PRI64d"\n"
|
||||
" nExpiration = %"PRI64d"\n"
|
||||
" nID = %d\n"
|
||||
" nCancel = %d\n"
|
||||
" setCancel = %s\n"
|
||||
" nMinVer = %d\n"
|
||||
" nMaxVer = %d\n"
|
||||
" setSubVer = %s\n"
|
||||
" nPriority = %d\n"
|
||||
" strComment = \"%s\"\n"
|
||||
" strStatusBar = \"%s\"\n"
|
||||
")\n",
|
||||
nVersion,
|
||||
nRelayUntil,
|
||||
nExpiration,
|
||||
nID,
|
||||
nCancel,
|
||||
strSetCancel.c_str(),
|
||||
nMinVer,
|
||||
nMaxVer,
|
||||
strSetSubVer.c_str(),
|
||||
nPriority,
|
||||
strComment.c_str(),
|
||||
strStatusBar.c_str());
|
||||
}
|
||||
|
||||
void CUnsignedAlert::print() const
|
||||
{
|
||||
printf("%s", ToString().c_str());
|
||||
}
|
||||
|
||||
void CAlert::SetNull()
|
||||
{
|
||||
CUnsignedAlert::SetNull();
|
||||
vchMsg.clear();
|
||||
vchSig.clear();
|
||||
}
|
||||
|
||||
bool CAlert::IsNull() const
|
||||
{
|
||||
return (nExpiration == 0);
|
||||
}
|
||||
|
||||
uint256 CAlert::GetHash() const
|
||||
{
|
||||
return Hash(this->vchMsg.begin(), this->vchMsg.end());
|
||||
}
|
||||
|
||||
bool CAlert::IsInEffect() const
|
||||
{
|
||||
return (GetAdjustedTime() < nExpiration);
|
||||
}
|
||||
|
||||
bool CAlert::Cancels(const CAlert& alert) const
|
||||
{
|
||||
if (!IsInEffect())
|
||||
return false; // this was a no-op before 31403
|
||||
return (alert.nID <= nCancel || setCancel.count(alert.nID));
|
||||
}
|
||||
|
||||
bool CAlert::AppliesTo(int nVersion, std::string strSubVerIn) const
|
||||
{
|
||||
// TODO: rework for client-version-embedded-in-strSubVer ?
|
||||
return (IsInEffect() &&
|
||||
nMinVer <= nVersion && nVersion <= nMaxVer &&
|
||||
(setSubVer.empty() || setSubVer.count(strSubVerIn)));
|
||||
}
|
||||
|
||||
bool CAlert::AppliesToMe() const
|
||||
{
|
||||
return AppliesTo(PROTOCOL_VERSION, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<std::string>()));
|
||||
}
|
||||
|
||||
bool CAlert::RelayTo(CNode* pnode) const
|
||||
{
|
||||
if (!IsInEffect())
|
||||
return false;
|
||||
// returns true if wasn't already contained in the set
|
||||
if (pnode->setKnown.insert(GetHash()).second)
|
||||
{
|
||||
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
|
||||
AppliesToMe() ||
|
||||
GetAdjustedTime() < nRelayUntil)
|
||||
{
|
||||
pnode->PushMessage("alert", *this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CAlert::CheckSignature() const
|
||||
{
|
||||
CKey key;
|
||||
if (!key.SetPubKey(ParseHex(fTestNet ? pszTestKey : pszMainKey)))
|
||||
return error("CAlert::CheckSignature() : SetPubKey failed");
|
||||
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
|
||||
return error("CAlert::CheckSignature() : verify signature failed");
|
||||
|
||||
// Now unserialize the data
|
||||
CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
|
||||
sMsg >> *(CUnsignedAlert*)this;
|
||||
return true;
|
||||
}
|
||||
|
||||
CAlert CAlert::getAlertByHash(const uint256 &hash)
|
||||
{
|
||||
CAlert retval;
|
||||
{
|
||||
LOCK(cs_mapAlerts);
|
||||
map<uint256, CAlert>::iterator mi = mapAlerts.find(hash);
|
||||
if(mi != mapAlerts.end())
|
||||
retval = mi->second;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool CAlert::ProcessAlert()
|
||||
{
|
||||
if (!CheckSignature())
|
||||
return false;
|
||||
if (!IsInEffect())
|
||||
return false;
|
||||
|
||||
// alert.nID=max is reserved for if the alert key is
|
||||
// compromised. It must have a pre-defined message,
|
||||
// must never expire, must apply to all versions,
|
||||
// and must cancel all previous
|
||||
// alerts or it will be ignored (so an attacker can't
|
||||
// send an "everything is OK, don't panic" version that
|
||||
// cannot be overridden):
|
||||
int maxInt = std::numeric_limits<int>::max();
|
||||
if (nID == maxInt)
|
||||
{
|
||||
if (!(
|
||||
nExpiration == maxInt &&
|
||||
nCancel == (maxInt-1) &&
|
||||
nMinVer == 0 &&
|
||||
nMaxVer == maxInt &&
|
||||
setSubVer.empty() &&
|
||||
nPriority == maxInt &&
|
||||
strStatusBar == "URGENT: Alert key compromised, upgrade required"
|
||||
))
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
LOCK(cs_mapAlerts);
|
||||
// Cancel previous alerts
|
||||
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
|
||||
{
|
||||
const CAlert& alert = (*mi).second;
|
||||
if (Cancels(alert))
|
||||
{
|
||||
printf("cancelling alert %d\n", alert.nID);
|
||||
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
|
||||
mapAlerts.erase(mi++);
|
||||
}
|
||||
else if (!alert.IsInEffect())
|
||||
{
|
||||
printf("expiring alert %d\n", alert.nID);
|
||||
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
|
||||
mapAlerts.erase(mi++);
|
||||
}
|
||||
else
|
||||
mi++;
|
||||
}
|
||||
|
||||
// Check if this alert has been cancelled
|
||||
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
|
||||
{
|
||||
const CAlert& alert = item.second;
|
||||
if (alert.Cancels(*this))
|
||||
{
|
||||
printf("alert already cancelled by %d\n", alert.nID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to mapAlerts
|
||||
mapAlerts.insert(make_pair(GetHash(), *this));
|
||||
// Notify UI if it applies to me
|
||||
if(AppliesToMe())
|
||||
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
|
||||
}
|
||||
|
||||
printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
|
||||
return true;
|
||||
}
|
||||
102
src/alert.h
Normal file
102
src/alert.h
Normal file
@@ -0,0 +1,102 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef _BITCOINALERT_H_
|
||||
#define _BITCOINALERT_H_ 1
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "uint256.h"
|
||||
#include "util.h"
|
||||
|
||||
class CNode;
|
||||
|
||||
/** Alerts are for notifying old versions if they become too obsolete and
|
||||
* need to upgrade. The message is displayed in the status bar.
|
||||
* Alert messages are broadcast as a vector of signed data. Unserializing may
|
||||
* not read the entire buffer if the alert is for a newer version, but older
|
||||
* versions can still relay the original data.
|
||||
*/
|
||||
class CUnsignedAlert
|
||||
{
|
||||
public:
|
||||
int nVersion;
|
||||
int64 nRelayUntil; // when newer nodes stop relaying to newer nodes
|
||||
int64 nExpiration;
|
||||
int nID;
|
||||
int nCancel;
|
||||
std::set<int> setCancel;
|
||||
int nMinVer; // lowest version inclusive
|
||||
int nMaxVer; // highest version inclusive
|
||||
std::set<std::string> setSubVer; // empty matches all
|
||||
int nPriority;
|
||||
|
||||
// Actions
|
||||
std::string strComment;
|
||||
std::string strStatusBar;
|
||||
std::string strReserved;
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(
|
||||
READWRITE(this->nVersion);
|
||||
nVersion = this->nVersion;
|
||||
READWRITE(nRelayUntil);
|
||||
READWRITE(nExpiration);
|
||||
READWRITE(nID);
|
||||
READWRITE(nCancel);
|
||||
READWRITE(setCancel);
|
||||
READWRITE(nMinVer);
|
||||
READWRITE(nMaxVer);
|
||||
READWRITE(setSubVer);
|
||||
READWRITE(nPriority);
|
||||
|
||||
READWRITE(strComment);
|
||||
READWRITE(strStatusBar);
|
||||
READWRITE(strReserved);
|
||||
)
|
||||
|
||||
void SetNull();
|
||||
|
||||
std::string ToString() const;
|
||||
void print() const;
|
||||
};
|
||||
|
||||
/** An alert is a combination of a serialized CUnsignedAlert and a signature. */
|
||||
class CAlert : public CUnsignedAlert
|
||||
{
|
||||
public:
|
||||
std::vector<unsigned char> vchMsg;
|
||||
std::vector<unsigned char> vchSig;
|
||||
|
||||
CAlert()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(
|
||||
READWRITE(vchMsg);
|
||||
READWRITE(vchSig);
|
||||
)
|
||||
|
||||
void SetNull();
|
||||
bool IsNull() const;
|
||||
uint256 GetHash() const;
|
||||
bool IsInEffect() const;
|
||||
bool Cancels(const CAlert& alert) const;
|
||||
bool AppliesTo(int nVersion, std::string strSubVerIn) const;
|
||||
bool AppliesToMe() const;
|
||||
bool RelayTo(CNode* pnode) const;
|
||||
bool CheckSignature() const;
|
||||
bool ProcessAlert();
|
||||
|
||||
/*
|
||||
* Get copy of (active) alert object by hash. Returns a null alert if it is not found.
|
||||
*/
|
||||
static CAlert getAlertByHash(const uint256 &hash);
|
||||
};
|
||||
|
||||
#endif
|
||||
257
src/allocators.h
Normal file
257
src/allocators.h
Normal file
@@ -0,0 +1,257 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_ALLOCATORS_H
|
||||
#define BITCOIN_ALLOCATORS_H
|
||||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <map>
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <windows.h>
|
||||
// This is used to attempt to keep keying material out of swap
|
||||
// Note that VirtualLock does not provide this as a guarantee on Windows,
|
||||
// but, in practice, memory that has been VirtualLock'd almost never gets written to
|
||||
// the pagefile except in rare circumstances where memory is extremely low.
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#include <limits.h> // for PAGESIZE
|
||||
#include <unistd.h> // for sysconf
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Thread-safe class to keep track of locked (ie, non-swappable) memory pages.
|
||||
*
|
||||
* Memory locks do not stack, that is, pages which have been locked several times by calls to mlock()
|
||||
* will be unlocked by a single call to munlock(). This can result in keying material ending up in swap when
|
||||
* those functions are used naively. This class simulates stacking memory locks by keeping a counter per page.
|
||||
*
|
||||
* @note By using a map from each page base address to lock count, this class is optimized for
|
||||
* small objects that span up to a few pages, mostly smaller than a page. To support large allocations,
|
||||
* something like an interval tree would be the preferred data structure.
|
||||
*/
|
||||
template <class Locker> class LockedPageManagerBase
|
||||
{
|
||||
public:
|
||||
LockedPageManagerBase(size_t page_size):
|
||||
page_size(page_size)
|
||||
{
|
||||
// Determine bitmask for extracting page from address
|
||||
assert(!(page_size & (page_size-1))); // size must be power of two
|
||||
page_mask = ~(page_size - 1);
|
||||
}
|
||||
|
||||
// For all pages in affected range, increase lock count
|
||||
void LockRange(void *p, size_t size)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
if(!size) return;
|
||||
const size_t base_addr = reinterpret_cast<size_t>(p);
|
||||
const size_t start_page = base_addr & page_mask;
|
||||
const size_t end_page = (base_addr + size - 1) & page_mask;
|
||||
for(size_t page = start_page; page <= end_page; page += page_size)
|
||||
{
|
||||
Histogram::iterator it = histogram.find(page);
|
||||
if(it == histogram.end()) // Newly locked page
|
||||
{
|
||||
locker.Lock(reinterpret_cast<void*>(page), page_size);
|
||||
histogram.insert(std::make_pair(page, 1));
|
||||
}
|
||||
else // Page was already locked; increase counter
|
||||
{
|
||||
it->second += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For all pages in affected range, decrease lock count
|
||||
void UnlockRange(void *p, size_t size)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
if(!size) return;
|
||||
const size_t base_addr = reinterpret_cast<size_t>(p);
|
||||
const size_t start_page = base_addr & page_mask;
|
||||
const size_t end_page = (base_addr + size - 1) & page_mask;
|
||||
for(size_t page = start_page; page <= end_page; page += page_size)
|
||||
{
|
||||
Histogram::iterator it = histogram.find(page);
|
||||
assert(it != histogram.end()); // Cannot unlock an area that was not locked
|
||||
// Decrease counter for page, when it is zero, the page will be unlocked
|
||||
it->second -= 1;
|
||||
if(it->second == 0) // Nothing on the page anymore that keeps it locked
|
||||
{
|
||||
// Unlock page and remove the count from histogram
|
||||
locker.Unlock(reinterpret_cast<void*>(page), page_size);
|
||||
histogram.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get number of locked pages for diagnostics
|
||||
int GetLockedPageCount()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
return histogram.size();
|
||||
}
|
||||
|
||||
private:
|
||||
Locker locker;
|
||||
boost::mutex mutex;
|
||||
size_t page_size, page_mask;
|
||||
// map of page base address to lock count
|
||||
typedef std::map<size_t,int> Histogram;
|
||||
Histogram histogram;
|
||||
};
|
||||
|
||||
/** Determine system page size in bytes */
|
||||
static inline size_t GetSystemPageSize()
|
||||
{
|
||||
size_t page_size;
|
||||
#if defined(WIN32)
|
||||
SYSTEM_INFO sSysInfo;
|
||||
GetSystemInfo(&sSysInfo);
|
||||
page_size = sSysInfo.dwPageSize;
|
||||
#elif defined(PAGESIZE) // defined in limits.h
|
||||
page_size = PAGESIZE;
|
||||
#else // assume some POSIX OS
|
||||
page_size = sysconf(_SC_PAGESIZE);
|
||||
#endif
|
||||
return page_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* OS-dependent memory page locking/unlocking.
|
||||
* Defined as policy class to make stubbing for test possible.
|
||||
*/
|
||||
class MemoryPageLocker
|
||||
{
|
||||
public:
|
||||
/** Lock memory pages.
|
||||
* addr and len must be a multiple of the system page size
|
||||
*/
|
||||
bool Lock(const void *addr, size_t len)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return VirtualLock(const_cast<void*>(addr), len);
|
||||
#else
|
||||
return mlock(addr, len) == 0;
|
||||
#endif
|
||||
}
|
||||
/** Unlock memory pages.
|
||||
* addr and len must be a multiple of the system page size
|
||||
*/
|
||||
bool Unlock(const void *addr, size_t len)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return VirtualUnlock(const_cast<void*>(addr), len);
|
||||
#else
|
||||
return munlock(addr, len) == 0;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Singleton class to keep track of locked (ie, non-swappable) memory pages, for use in
|
||||
* std::allocator templates.
|
||||
*/
|
||||
class LockedPageManager: public LockedPageManagerBase<MemoryPageLocker>
|
||||
{
|
||||
public:
|
||||
static LockedPageManager instance; // instantiated in util.cpp
|
||||
private:
|
||||
LockedPageManager():
|
||||
LockedPageManagerBase<MemoryPageLocker>(GetSystemPageSize())
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// Allocator that locks its contents from being paged
|
||||
// out of memory and clears its contents before deletion.
|
||||
//
|
||||
template<typename T>
|
||||
struct secure_allocator : public std::allocator<T>
|
||||
{
|
||||
// MSVC8 default copy constructor is broken
|
||||
typedef std::allocator<T> base;
|
||||
typedef typename base::size_type size_type;
|
||||
typedef typename base::difference_type difference_type;
|
||||
typedef typename base::pointer pointer;
|
||||
typedef typename base::const_pointer const_pointer;
|
||||
typedef typename base::reference reference;
|
||||
typedef typename base::const_reference const_reference;
|
||||
typedef typename base::value_type value_type;
|
||||
secure_allocator() throw() {}
|
||||
secure_allocator(const secure_allocator& a) throw() : base(a) {}
|
||||
template <typename U>
|
||||
secure_allocator(const secure_allocator<U>& a) throw() : base(a) {}
|
||||
~secure_allocator() throw() {}
|
||||
template<typename _Other> struct rebind
|
||||
{ typedef secure_allocator<_Other> other; };
|
||||
|
||||
T* allocate(std::size_t n, const void *hint = 0)
|
||||
{
|
||||
T *p;
|
||||
p = std::allocator<T>::allocate(n, hint);
|
||||
if (p != NULL)
|
||||
LockedPageManager::instance.LockRange(p, sizeof(T) * n);
|
||||
return p;
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t n)
|
||||
{
|
||||
if (p != NULL)
|
||||
{
|
||||
memset(p, 0, sizeof(T) * n);
|
||||
LockedPageManager::instance.UnlockRange(p, sizeof(T) * n);
|
||||
}
|
||||
std::allocator<T>::deallocate(p, n);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Allocator that clears its contents before deletion.
|
||||
//
|
||||
template<typename T>
|
||||
struct zero_after_free_allocator : public std::allocator<T>
|
||||
{
|
||||
// MSVC8 default copy constructor is broken
|
||||
typedef std::allocator<T> base;
|
||||
typedef typename base::size_type size_type;
|
||||
typedef typename base::difference_type difference_type;
|
||||
typedef typename base::pointer pointer;
|
||||
typedef typename base::const_pointer const_pointer;
|
||||
typedef typename base::reference reference;
|
||||
typedef typename base::const_reference const_reference;
|
||||
typedef typename base::value_type value_type;
|
||||
zero_after_free_allocator() throw() {}
|
||||
zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {}
|
||||
template <typename U>
|
||||
zero_after_free_allocator(const zero_after_free_allocator<U>& a) throw() : base(a) {}
|
||||
~zero_after_free_allocator() throw() {}
|
||||
template<typename _Other> struct rebind
|
||||
{ typedef zero_after_free_allocator<_Other> other; };
|
||||
|
||||
void deallocate(T* p, std::size_t n)
|
||||
{
|
||||
if (p != NULL)
|
||||
memset(p, 0, sizeof(T) * n);
|
||||
std::allocator<T>::deallocate(p, n);
|
||||
}
|
||||
};
|
||||
|
||||
// This is exactly like std::string, but with a custom allocator.
|
||||
typedef std::basic_string<char, std::char_traits<char>, secure_allocator<char> > SecureString;
|
||||
|
||||
#endif
|
||||
141
src/base58.h
141
src/base58.h
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin Developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
||||
//
|
||||
@@ -10,7 +10,7 @@
|
||||
// could be used to create visually identical looking account numbers.
|
||||
// - A string with non-alphanumeric characters is not as easily accepted as an account number.
|
||||
// - E-mail usually won't line-break if there's no punctuation to break at.
|
||||
// - Doubleclicking selects the whole number as one word if it's all alphanumeric.
|
||||
// - Double-clicking selects the whole number as one word if it's all alphanumeric.
|
||||
//
|
||||
#ifndef BITCOIN_BASE58_H
|
||||
#define BITCOIN_BASE58_H
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
#include "bignum.h"
|
||||
#include "key.h"
|
||||
#include "script.h"
|
||||
|
||||
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
|
||||
@@ -70,7 +71,7 @@ inline std::string EncodeBase58(const std::vector<unsigned char>& vch)
|
||||
}
|
||||
|
||||
// Decode a base58-encoded string psz into byte vector vchRet
|
||||
// returns true if decoding is succesful
|
||||
// returns true if decoding is successful
|
||||
inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
|
||||
{
|
||||
CAutoBN_CTX pctx;
|
||||
@@ -118,7 +119,7 @@ inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
|
||||
}
|
||||
|
||||
// Decode a base58-encoded string str into byte vector vchRet
|
||||
// returns true if decoding is succesful
|
||||
// returns true if decoding is successful
|
||||
inline bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet)
|
||||
{
|
||||
return DecodeBase58(str.c_str(), vchRet);
|
||||
@@ -138,7 +139,7 @@ inline std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn)
|
||||
}
|
||||
|
||||
// Decode a base58-encoded string psz that includes a checksum, into byte vector vchRet
|
||||
// returns true if decoding is succesful
|
||||
// returns true if decoding is successful
|
||||
inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet)
|
||||
{
|
||||
if (!DecodeBase58(psz, vchRet))
|
||||
@@ -159,7 +160,7 @@ inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRe
|
||||
}
|
||||
|
||||
// Decode a base58-encoded string str that includes a checksum, into byte vector vchRet
|
||||
// returns true if decoding is succesful
|
||||
// returns true if decoding is successful
|
||||
inline bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet)
|
||||
{
|
||||
return DecodeBase58Check(str.c_str(), vchRet);
|
||||
@@ -169,7 +170,7 @@ inline bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>
|
||||
|
||||
|
||||
|
||||
// Base class for all base58-encoded data
|
||||
/** Base class for all base58-encoded data */
|
||||
class CBase58Data
|
||||
{
|
||||
protected:
|
||||
@@ -252,11 +253,24 @@ public:
|
||||
bool operator> (const CBase58Data& b58) const { return CompareTo(b58) > 0; }
|
||||
};
|
||||
|
||||
// base58-encoded bitcoin addresses
|
||||
// Public-key-hash-addresses have version 0 (or 192 testnet)
|
||||
// The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key
|
||||
// Script-hash-addresses have version 5 (or 196 testnet)
|
||||
// The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script
|
||||
/** base58-encoded Bitcoin addresses.
|
||||
* Public-key-hash-addresses have version 0 (or 111 testnet).
|
||||
* The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key.
|
||||
* Script-hash-addresses have version 5 (or 196 testnet).
|
||||
* The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
|
||||
*/
|
||||
class CBitcoinAddress;
|
||||
class CBitcoinAddressVisitor : public boost::static_visitor<bool>
|
||||
{
|
||||
private:
|
||||
CBitcoinAddress *addr;
|
||||
public:
|
||||
CBitcoinAddressVisitor(CBitcoinAddress *addrIn) : addr(addrIn) { }
|
||||
bool operator()(const CKeyID &id) const;
|
||||
bool operator()(const CScriptID &id) const;
|
||||
bool operator()(const CNoDestination &no) const;
|
||||
};
|
||||
|
||||
class CBitcoinAddress : public CBase58Data
|
||||
{
|
||||
public:
|
||||
@@ -268,26 +282,24 @@ public:
|
||||
SCRIPT_ADDRESS_TEST = 196,
|
||||
};
|
||||
|
||||
bool SetHash160(const uint160& hash160)
|
||||
{
|
||||
SetData(fTestNet ? PUBKEY_ADDRESS_TEST : PUBKEY_ADDRESS, &hash160, 20);
|
||||
bool Set(const CKeyID &id) {
|
||||
SetData(fTestNet ? PUBKEY_ADDRESS_TEST : PUBKEY_ADDRESS, &id, 20);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetPubKey(const std::vector<unsigned char>& vchPubKey)
|
||||
{
|
||||
SetHash160(Hash160(vchPubKey));
|
||||
bool Set(const CScriptID &id) {
|
||||
SetData(fTestNet ? SCRIPT_ADDRESS_TEST : SCRIPT_ADDRESS, &id, 20);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetScriptHash160(const uint160& hash160)
|
||||
bool Set(const CTxDestination &dest)
|
||||
{
|
||||
SetData(fTestNet ? SCRIPT_ADDRESS_TEST : SCRIPT_ADDRESS, &hash160, 20);
|
||||
return true;
|
||||
return boost::apply_visitor(CBitcoinAddressVisitor(this), dest);
|
||||
}
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
int nExpectedSize = 20;
|
||||
unsigned int nExpectedSize = 20;
|
||||
bool fExpectTestNet = false;
|
||||
switch(nVersion)
|
||||
{
|
||||
@@ -314,27 +326,14 @@ public:
|
||||
}
|
||||
return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize;
|
||||
}
|
||||
bool IsScript() const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
if (fTestNet)
|
||||
return nVersion == SCRIPT_ADDRESS_TEST;
|
||||
return nVersion == SCRIPT_ADDRESS;
|
||||
}
|
||||
|
||||
CBitcoinAddress()
|
||||
{
|
||||
}
|
||||
|
||||
CBitcoinAddress(uint160 hash160In)
|
||||
CBitcoinAddress(const CTxDestination &dest)
|
||||
{
|
||||
SetHash160(hash160In);
|
||||
}
|
||||
|
||||
CBitcoinAddress(const std::vector<unsigned char>& vchPubKey)
|
||||
{
|
||||
SetPubKey(vchPubKey);
|
||||
Set(dest);
|
||||
}
|
||||
|
||||
CBitcoinAddress(const std::string& strAddress)
|
||||
@@ -347,20 +346,64 @@ public:
|
||||
SetString(pszAddress);
|
||||
}
|
||||
|
||||
uint160 GetHash160() const
|
||||
{
|
||||
assert(vchData.size() == 20);
|
||||
uint160 hash160;
|
||||
memcpy(&hash160, &vchData[0], 20);
|
||||
return hash160;
|
||||
CTxDestination Get() const {
|
||||
if (!IsValid())
|
||||
return CNoDestination();
|
||||
switch (nVersion) {
|
||||
case PUBKEY_ADDRESS:
|
||||
case PUBKEY_ADDRESS_TEST: {
|
||||
uint160 id;
|
||||
memcpy(&id, &vchData[0], 20);
|
||||
return CKeyID(id);
|
||||
}
|
||||
case SCRIPT_ADDRESS:
|
||||
case SCRIPT_ADDRESS_TEST: {
|
||||
uint160 id;
|
||||
memcpy(&id, &vchData[0], 20);
|
||||
return CScriptID(id);
|
||||
}
|
||||
}
|
||||
return CNoDestination();
|
||||
}
|
||||
|
||||
bool GetKeyID(CKeyID &keyID) const {
|
||||
if (!IsValid())
|
||||
return false;
|
||||
switch (nVersion) {
|
||||
case PUBKEY_ADDRESS:
|
||||
case PUBKEY_ADDRESS_TEST: {
|
||||
uint160 id;
|
||||
memcpy(&id, &vchData[0], 20);
|
||||
keyID = CKeyID(id);
|
||||
return true;
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsScript() const {
|
||||
if (!IsValid())
|
||||
return false;
|
||||
switch (nVersion) {
|
||||
case SCRIPT_ADDRESS:
|
||||
case SCRIPT_ADDRESS_TEST: {
|
||||
return true;
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool inline CBitcoinAddressVisitor::operator()(const CKeyID &id) const { return addr->Set(id); }
|
||||
bool inline CBitcoinAddressVisitor::operator()(const CScriptID &id) const { return addr->Set(id); }
|
||||
bool inline CBitcoinAddressVisitor::operator()(const CNoDestination &id) const { return false; }
|
||||
|
||||
/** A base58-encoded secret key */
|
||||
class CBitcoinSecret : public CBase58Data
|
||||
{
|
||||
public:
|
||||
void SetSecret(const CSecret& vchSecret, bool fCompressed)
|
||||
{
|
||||
{
|
||||
assert(vchSecret.size() == 32);
|
||||
SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size());
|
||||
if (fCompressed)
|
||||
@@ -394,6 +437,16 @@ public:
|
||||
return fExpectTestNet == fTestNet && (vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1));
|
||||
}
|
||||
|
||||
bool SetString(const char* pszSecret)
|
||||
{
|
||||
return CBase58Data::SetString(pszSecret) && IsValid();
|
||||
}
|
||||
|
||||
bool SetString(const std::string& strSecret)
|
||||
{
|
||||
return SetString(strSecret.c_str());
|
||||
}
|
||||
|
||||
CBitcoinSecret(const CSecret& vchSecret, bool fCompressed)
|
||||
{
|
||||
SetSecret(vchSecret, fCompressed);
|
||||
|
||||
42
src/bignum.h
42
src/bignum.h
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_BIGNUM_H
|
||||
#define BITCOIN_BIGNUM_H
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
#include <vector>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "util.h" // for uint64
|
||||
|
||||
/** Errors thrown by the bignum class */
|
||||
class bignum_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
@@ -18,7 +19,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** RAII encapsulated BN_CTX (OpenSSL bignum context) */
|
||||
class CAutoBN_CTX
|
||||
{
|
||||
protected:
|
||||
@@ -46,7 +47,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** C++ wrapper for BIGNUM (OpenSSL bignum) */
|
||||
class CBigNum : public BIGNUM
|
||||
{
|
||||
public:
|
||||
@@ -77,7 +78,8 @@ public:
|
||||
BN_clear_free(this);
|
||||
}
|
||||
|
||||
CBigNum(char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
//CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
|
||||
CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
|
||||
@@ -115,21 +117,29 @@ public:
|
||||
{
|
||||
unsigned long n = BN_get_word(this);
|
||||
if (!BN_is_negative(this))
|
||||
return (n > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
|
||||
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
|
||||
else
|
||||
return (n > std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
|
||||
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
|
||||
}
|
||||
|
||||
void setint64(int64 n)
|
||||
void setint64(int64 sn)
|
||||
{
|
||||
unsigned char pch[sizeof(n) + 6];
|
||||
unsigned char pch[sizeof(sn) + 6];
|
||||
unsigned char* p = pch + 4;
|
||||
bool fNegative = false;
|
||||
if (n < (int64)0)
|
||||
bool fNegative;
|
||||
uint64 n;
|
||||
|
||||
if (sn < (int64)0)
|
||||
{
|
||||
n = -n;
|
||||
// Since the minimum signed integer cannot be represented as positive so long as its type is signed, and it's not well-defined what happens if you make it unsigned before negating it, we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
|
||||
n = -(sn + 1);
|
||||
++n;
|
||||
fNegative = true;
|
||||
} else {
|
||||
n = sn;
|
||||
fNegative = false;
|
||||
}
|
||||
|
||||
bool fLeadingZeroes = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
@@ -220,7 +230,7 @@ public:
|
||||
if (vch.size() > 4)
|
||||
vch[4] &= 0x7f;
|
||||
uint256 n = 0;
|
||||
for (int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
|
||||
for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
|
||||
((unsigned char*)&n)[i] = vch[j];
|
||||
return n;
|
||||
}
|
||||
@@ -295,12 +305,12 @@ public:
|
||||
psz++;
|
||||
|
||||
// hex string to bignum
|
||||
static char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
|
||||
static const signed char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
|
||||
*this = 0;
|
||||
while (isxdigit(*psz))
|
||||
{
|
||||
*this <<= 4;
|
||||
int n = phexdigit[*psz++];
|
||||
int n = phexdigit[(unsigned char)*psz++];
|
||||
*this += n;
|
||||
}
|
||||
if (fNegative)
|
||||
@@ -406,7 +416,7 @@ public:
|
||||
CBigNum& operator>>=(unsigned int shift)
|
||||
{
|
||||
// Note: BN_rshift segfaults on 64-bit if 2^shift is greater than the number
|
||||
// if built on ubuntu 9.04 or 9.10, probably depends on version of openssl
|
||||
// if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
|
||||
CBigNum a = 1;
|
||||
a <<= shift;
|
||||
if (BN_cmp(&a, this) > 0)
|
||||
|
||||
2900
src/bitcoinrpc.cpp
2900
src/bitcoinrpc.cpp
File diff suppressed because it is too large
Load Diff
186
src/bitcoinrpc.h
186
src/bitcoinrpc.h
@@ -1,7 +1,191 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef _BITCOINRPC_H_
|
||||
#define _BITCOINRPC_H_ 1
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
class CBlockIndex;
|
||||
|
||||
#include "json/json_spirit_reader_template.h"
|
||||
#include "json/json_spirit_writer_template.h"
|
||||
#include "json/json_spirit_utils.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
// HTTP status codes
|
||||
enum HTTPStatusCode
|
||||
{
|
||||
HTTP_OK = 200,
|
||||
HTTP_BAD_REQUEST = 400,
|
||||
HTTP_UNAUTHORIZED = 401,
|
||||
HTTP_FORBIDDEN = 403,
|
||||
HTTP_NOT_FOUND = 404,
|
||||
HTTP_INTERNAL_SERVER_ERROR = 500,
|
||||
};
|
||||
|
||||
// Bitcoin RPC error codes
|
||||
enum RPCErrorCode
|
||||
{
|
||||
// Standard JSON-RPC 2.0 errors
|
||||
RPC_INVALID_REQUEST = -32600,
|
||||
RPC_METHOD_NOT_FOUND = -32601,
|
||||
RPC_INVALID_PARAMS = -32602,
|
||||
RPC_INTERNAL_ERROR = -32603,
|
||||
RPC_PARSE_ERROR = -32700,
|
||||
|
||||
// General application defined errors
|
||||
RPC_MISC_ERROR = -1, // std::exception thrown in command handling
|
||||
RPC_FORBIDDEN_BY_SAFE_MODE = -2, // Server is in safe mode, and command is not allowed in safe mode
|
||||
RPC_TYPE_ERROR = -3, // Unexpected type was passed as parameter
|
||||
RPC_INVALID_ADDRESS_OR_KEY = -5, // Invalid address or key
|
||||
RPC_OUT_OF_MEMORY = -7, // Ran out of memory during operation
|
||||
RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter
|
||||
RPC_DATABASE_ERROR = -20, // Database error
|
||||
RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format
|
||||
|
||||
// P2P client errors
|
||||
RPC_CLIENT_NOT_CONNECTED = -9, // Bitcoin is not connected
|
||||
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, // Still downloading initial blocks
|
||||
|
||||
// Wallet errors
|
||||
RPC_WALLET_ERROR = -4, // Unspecified problem with wallet (key not found etc.)
|
||||
RPC_WALLET_INSUFFICIENT_FUNDS = -6, // Not enough funds in wallet or account
|
||||
RPC_WALLET_INVALID_ACCOUNT_NAME = -11, // Invalid account name
|
||||
RPC_WALLET_KEYPOOL_RAN_OUT = -12, // Keypool ran out, call keypoolrefill first
|
||||
RPC_WALLET_UNLOCK_NEEDED = -13, // Enter the wallet passphrase with walletpassphrase first
|
||||
RPC_WALLET_PASSPHRASE_INCORRECT = -14, // The wallet passphrase entered was incorrect
|
||||
RPC_WALLET_WRONG_ENC_STATE = -15, // Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
|
||||
RPC_WALLET_ENCRYPTION_FAILED = -16, // Failed to encrypt the wallet
|
||||
RPC_WALLET_ALREADY_UNLOCKED = -17, // Wallet is already unlocked
|
||||
};
|
||||
|
||||
json_spirit::Object JSONRPCError(int code, const std::string& message);
|
||||
|
||||
void ThreadRPCServer(void* parg);
|
||||
int CommandLineRPC(int argc, char *argv[]);
|
||||
|
||||
/** Convert parameter values for RPC call from strings to command-specific JSON objects. */
|
||||
json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams);
|
||||
|
||||
/*
|
||||
Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
|
||||
the right number of arguments are passed, just that any passed are the correct type.
|
||||
Use like: RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
|
||||
*/
|
||||
void RPCTypeCheck(const json_spirit::Array& params,
|
||||
const std::list<json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
|
||||
/*
|
||||
Check for expected keys/value types in an Object.
|
||||
Use like: RPCTypeCheck(object, boost::assign::map_list_of("name", str_type)("value", int_type));
|
||||
*/
|
||||
void RPCTypeCheck(const json_spirit::Object& o,
|
||||
const std::map<std::string, json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
|
||||
|
||||
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
class CRPCCommand
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
rpcfn_type actor;
|
||||
bool okSafeMode;
|
||||
bool unlocked;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bitcoin RPC command dispatcher.
|
||||
*/
|
||||
class CRPCTable
|
||||
{
|
||||
private:
|
||||
std::map<std::string, const CRPCCommand*> mapCommands;
|
||||
public:
|
||||
CRPCTable();
|
||||
const CRPCCommand* operator[](std::string name) const;
|
||||
std::string help(std::string name) const;
|
||||
|
||||
/**
|
||||
* Execute a method.
|
||||
* @param method Method to execute
|
||||
* @param params Array of arguments (JSON objects)
|
||||
* @returns Result of the call.
|
||||
* @throws an exception (json_spirit::Value) when an error happens.
|
||||
*/
|
||||
json_spirit::Value execute(const std::string &method, const json_spirit::Array ¶ms) const;
|
||||
};
|
||||
|
||||
extern const CRPCTable tableRPC;
|
||||
|
||||
extern int64 nWalletUnlockTime;
|
||||
extern int64 AmountFromValue(const json_spirit::Value& value);
|
||||
extern json_spirit::Value ValueFromAmount(int64 amount);
|
||||
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
|
||||
extern std::string HexBits(unsigned int nBits);
|
||||
extern std::string HelpRequiringPassphrase();
|
||||
extern void EnsureWalletIsUnlocked();
|
||||
|
||||
extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
|
||||
extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
||||
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
|
||||
extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value gethashespersec(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
|
||||
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
|
||||
extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "headers.h"
|
||||
#include "checkpoints.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "uint256.h"
|
||||
|
||||
namespace Checkpoints
|
||||
{
|
||||
typedef std::map<int, uint256> MapCheckpoints;
|
||||
@@ -23,37 +25,39 @@ namespace Checkpoints
|
||||
boost::assign::map_list_of
|
||||
( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
|
||||
( 33333, uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
|
||||
( 68555, uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"))
|
||||
( 70567, uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a"))
|
||||
( 74000, uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20"))
|
||||
(105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97"))
|
||||
(118000, uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553"))
|
||||
(134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
|
||||
(140700, uint256("0x000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd"))
|
||||
(168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763"))
|
||||
(193000, uint256("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317"))
|
||||
;
|
||||
|
||||
static MapCheckpoints mapCheckpointsTestnet =
|
||||
boost::assign::map_list_of
|
||||
( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
|
||||
;
|
||||
|
||||
bool CheckBlock(int nHeight, const uint256& hash)
|
||||
{
|
||||
if (fTestNet) return true; // Testnet has no checkpoints
|
||||
MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);
|
||||
|
||||
MapCheckpoints::const_iterator i = mapCheckpoints.find(nHeight);
|
||||
if (i == mapCheckpoints.end()) return true;
|
||||
MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
|
||||
if (i == checkpoints.end()) return true;
|
||||
return hash == i->second;
|
||||
}
|
||||
|
||||
int GetTotalBlocksEstimate()
|
||||
{
|
||||
if (fTestNet) return 0;
|
||||
MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);
|
||||
|
||||
return mapCheckpoints.rbegin()->first;
|
||||
return checkpoints.rbegin()->first;
|
||||
}
|
||||
|
||||
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
|
||||
{
|
||||
if (fTestNet) return NULL;
|
||||
MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);
|
||||
|
||||
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints)
|
||||
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
|
||||
{
|
||||
const uint256& hash = i.second;
|
||||
std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_CHECKPOINT_H
|
||||
#define BITCOIN_CHECKPOINT_H
|
||||
|
||||
#include <map>
|
||||
#include "util.h"
|
||||
|
||||
class uint256;
|
||||
class CBlockIndex;
|
||||
|
||||
//
|
||||
// Block-chain checkpoints are compiled-in sanity checks.
|
||||
// They are updated every release or three.
|
||||
//
|
||||
/** Block-chain checkpoints are compiled-in sanity checks.
|
||||
* They are updated every release or three.
|
||||
*/
|
||||
namespace Checkpoints
|
||||
{
|
||||
// Returns true if block passes checkpoint checks
|
||||
|
||||
19
src/clientversion.h
Normal file
19
src/clientversion.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef CLIENTVERSION_H
|
||||
#define CLIENTVERSION_H
|
||||
|
||||
//
|
||||
// client versioning
|
||||
//
|
||||
|
||||
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
|
||||
#define CLIENT_VERSION_MAJOR 0
|
||||
#define CLIENT_VERSION_MINOR 7
|
||||
#define CLIENT_VERSION_REVISION 1
|
||||
#define CLIENT_VERSION_BUILD 0
|
||||
|
||||
// Converts the parameter X to a string after macro replacement on X has been performed.
|
||||
// Don't merge these into one macro!
|
||||
#define STRINGIZE(X) DO_STRINGIZE(X)
|
||||
#define DO_STRINGIZE(X) #X
|
||||
|
||||
#endif // CLIENTVERSION_H
|
||||
23
src/compat.h
23
src/compat.h
@@ -1,10 +1,30 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef _BITCOIN_COMPAT_H
|
||||
#define _BITCOIN_COMPAT_H 1
|
||||
|
||||
#ifdef WIN32
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <mswsock.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
typedef u_int SOCKET;
|
||||
#ifdef WIN32
|
||||
#define MSG_NOSIGNAL 0
|
||||
@@ -39,4 +59,5 @@ inline int myclosesocket(SOCKET& hSocket)
|
||||
}
|
||||
#define closesocket(s) myclosesocket(s)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,32 +6,23 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "headers.h"
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "crypter.h"
|
||||
#include "main.h"
|
||||
#include "util.h"
|
||||
|
||||
bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
|
||||
{
|
||||
if (nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE)
|
||||
return false;
|
||||
|
||||
// Try to keep the keydata out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap)
|
||||
// Note that this does nothing about suspend-to-disk (which will put all our key data on disk)
|
||||
// Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process.
|
||||
mlock(&chKey[0], sizeof chKey);
|
||||
mlock(&chIV[0], sizeof chIV);
|
||||
|
||||
int i = 0;
|
||||
if (nDerivationMethod == 0)
|
||||
i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha512(), &chSalt[0],
|
||||
(unsigned char *)&strKeyData[0], strKeyData.size(), nRounds, chKey, chIV);
|
||||
|
||||
if (i != WALLET_CRYPTO_KEY_SIZE)
|
||||
if (i != (int)WALLET_CRYPTO_KEY_SIZE)
|
||||
{
|
||||
memset(&chKey, 0, sizeof chKey);
|
||||
memset(&chIV, 0, sizeof chIV);
|
||||
@@ -47,12 +38,6 @@ bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector<unsigne
|
||||
if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE)
|
||||
return false;
|
||||
|
||||
// Try to keep the keydata out of swap
|
||||
// Note that this does nothing about suspend-to-disk (which will put all our key data on disk)
|
||||
// Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process.
|
||||
mlock(&chKey[0], sizeof chKey);
|
||||
mlock(&chIV[0], sizeof chIV);
|
||||
|
||||
memcpy(&chKey[0], &chNewKey[0], sizeof chKey);
|
||||
memcpy(&chIV[0], &chNewIV[0], sizeof chIV);
|
||||
|
||||
@@ -73,14 +58,16 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned
|
||||
|
||||
EVP_CIPHER_CTX ctx;
|
||||
|
||||
bool fOk = true;
|
||||
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
|
||||
|
||||
EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen);
|
||||
EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen);
|
||||
|
||||
if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
|
||||
if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen);
|
||||
if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen);
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
|
||||
if (!fOk) return false;
|
||||
|
||||
vchCiphertext.resize(nCLen + nFLen);
|
||||
return true;
|
||||
}
|
||||
@@ -98,14 +85,16 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM
|
||||
|
||||
EVP_CIPHER_CTX ctx;
|
||||
|
||||
bool fOk = true;
|
||||
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
|
||||
|
||||
EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
|
||||
EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen);
|
||||
|
||||
if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
|
||||
if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
|
||||
if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen);
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
|
||||
if (!fOk) return false;
|
||||
|
||||
vchPlaintext.resize(nPLen + nFLen);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
#ifndef __CRYPTER_H__
|
||||
#define __CRYPTER_H__
|
||||
|
||||
#include "util.h" /* for SecureString */
|
||||
#include "allocators.h" /* for SecureString */
|
||||
#include "key.h"
|
||||
#include "serialize.h"
|
||||
|
||||
const unsigned int WALLET_CRYPTO_KEY_SIZE = 32;
|
||||
const unsigned int WALLET_CRYPTO_SALT_SIZE = 8;
|
||||
@@ -25,6 +26,7 @@ with the double-sha256 of the public key as the IV, and the
|
||||
master key's key as the encryption key (see keystore.[ch]).
|
||||
*/
|
||||
|
||||
/** Master key for wallet encryption */
|
||||
class CMasterKey
|
||||
{
|
||||
public:
|
||||
@@ -58,6 +60,7 @@ public:
|
||||
|
||||
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
|
||||
|
||||
/** Encryption/decryption context with key information */
|
||||
class CCrypter
|
||||
{
|
||||
private:
|
||||
@@ -75,19 +78,26 @@ public:
|
||||
{
|
||||
memset(&chKey, 0, sizeof chKey);
|
||||
memset(&chIV, 0, sizeof chIV);
|
||||
munlock(&chKey, sizeof chKey);
|
||||
munlock(&chIV, sizeof chIV);
|
||||
fKeySet = false;
|
||||
}
|
||||
|
||||
CCrypter()
|
||||
{
|
||||
fKeySet = false;
|
||||
|
||||
// Try to keep the key data out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap)
|
||||
// Note that this does nothing about suspend-to-disk (which will put all our key data on disk)
|
||||
// Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process.
|
||||
LockedPageManager::instance.LockRange(&chKey[0], sizeof chKey);
|
||||
LockedPageManager::instance.LockRange(&chIV[0], sizeof chIV);
|
||||
}
|
||||
|
||||
~CCrypter()
|
||||
{
|
||||
CleanKey();
|
||||
|
||||
LockedPageManager::instance.UnlockRange(&chKey[0], sizeof chKey);
|
||||
LockedPageManager::instance.UnlockRange(&chIV[0], sizeof chIV);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
1132
src/db.cpp
1132
src/db.cpp
File diff suppressed because it is too large
Load Diff
350
src/db.h
350
src/db.h
@@ -1,11 +1,11 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_DB_H
|
||||
#define BITCOIN_DB_H
|
||||
|
||||
#include "key.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -13,9 +13,8 @@
|
||||
|
||||
#include <db_cxx.h>
|
||||
|
||||
class CAccount;
|
||||
class CAccountingEntry;
|
||||
class CAddress;
|
||||
class CAddrMan;
|
||||
class CBlockLocator;
|
||||
class CDiskBlockIndex;
|
||||
class CDiskTxPos;
|
||||
@@ -26,20 +25,80 @@ class CWallet;
|
||||
class CWalletTx;
|
||||
|
||||
extern unsigned int nWalletDBUpdated;
|
||||
extern DbEnv dbenv;
|
||||
|
||||
extern void DBFlush(bool fShutdown);
|
||||
void ThreadFlushWalletDB(void* parg);
|
||||
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
|
||||
|
||||
|
||||
class CDBEnv
|
||||
{
|
||||
private:
|
||||
bool fDetachDB;
|
||||
bool fDbEnvInit;
|
||||
bool fMockDb;
|
||||
boost::filesystem::path pathEnv;
|
||||
|
||||
void EnvShutdown();
|
||||
|
||||
public:
|
||||
mutable CCriticalSection cs_db;
|
||||
DbEnv dbenv;
|
||||
std::map<std::string, int> mapFileUseCount;
|
||||
std::map<std::string, Db*> mapDb;
|
||||
|
||||
CDBEnv();
|
||||
~CDBEnv();
|
||||
void MakeMock();
|
||||
bool IsMock() { return fMockDb; };
|
||||
|
||||
/*
|
||||
* Verify that database file strFile is OK. If it is not,
|
||||
* call the callback to try to recover.
|
||||
* This must be called BEFORE strFile is opened.
|
||||
* Returns true if strFile is OK.
|
||||
*/
|
||||
enum VerifyResult { VERIFY_OK, RECOVER_OK, RECOVER_FAIL };
|
||||
VerifyResult Verify(std::string strFile, bool (*recoverFunc)(CDBEnv& dbenv, std::string strFile));
|
||||
/*
|
||||
* Salvage data from a file that Verify says is bad.
|
||||
* fAggressive sets the DB_AGGRESSIVE flag (see berkeley DB->verify() method documentation).
|
||||
* Appends binary key/value pairs to vResult, returns true if successful.
|
||||
* NOTE: reads the entire database into memory, so cannot be used
|
||||
* for huge databases.
|
||||
*/
|
||||
typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
|
||||
bool Salvage(std::string strFile, bool fAggressive, std::vector<KeyValPair>& vResult);
|
||||
|
||||
bool Open(boost::filesystem::path pathEnv_);
|
||||
void Close();
|
||||
void Flush(bool fShutdown);
|
||||
void CheckpointLSN(std::string strFile);
|
||||
void SetDetach(bool fDetachDB_) { fDetachDB = fDetachDB_; }
|
||||
bool GetDetach() { return fDetachDB; }
|
||||
|
||||
void CloseDb(const std::string& strFile);
|
||||
bool RemoveDb(const std::string& strFile);
|
||||
|
||||
DbTxn *TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)
|
||||
{
|
||||
DbTxn* ptxn = NULL;
|
||||
int ret = dbenv.txn_begin(NULL, &ptxn, flags);
|
||||
if (!ptxn || ret != 0)
|
||||
return NULL;
|
||||
return ptxn;
|
||||
}
|
||||
};
|
||||
|
||||
extern CDBEnv bitdb;
|
||||
|
||||
|
||||
/** RAII class that provides access to a Berkeley database */
|
||||
class CDB
|
||||
{
|
||||
protected:
|
||||
Db* pdb;
|
||||
std::string strFile;
|
||||
std::vector<DbTxn*> vTxn;
|
||||
DbTxn *activeTxn;
|
||||
bool fReadOnly;
|
||||
|
||||
explicit CDB(const char* pszFile, const char* pszMode="r+");
|
||||
@@ -58,7 +117,7 @@ protected:
|
||||
return false;
|
||||
|
||||
// Key
|
||||
CDataStream ssKey(SER_DISK);
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(1000);
|
||||
ssKey << key;
|
||||
Dbt datKey(&ssKey[0], ssKey.size());
|
||||
@@ -66,14 +125,19 @@ protected:
|
||||
// Read
|
||||
Dbt datValue;
|
||||
datValue.set_flags(DB_DBT_MALLOC);
|
||||
int ret = pdb->get(GetTxn(), &datKey, &datValue, 0);
|
||||
int ret = pdb->get(activeTxn, &datKey, &datValue, 0);
|
||||
memset(datKey.get_data(), 0, datKey.get_size());
|
||||
if (datValue.get_data() == NULL)
|
||||
return false;
|
||||
|
||||
// Unserialize value
|
||||
CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK);
|
||||
ssValue >> value;
|
||||
try {
|
||||
CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK, CLIENT_VERSION);
|
||||
ssValue >> value;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear and free memory
|
||||
memset(datValue.get_data(), 0, datValue.get_size());
|
||||
@@ -90,19 +154,19 @@ protected:
|
||||
assert(!"Write called on database in read-only mode");
|
||||
|
||||
// Key
|
||||
CDataStream ssKey(SER_DISK);
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(1000);
|
||||
ssKey << key;
|
||||
Dbt datKey(&ssKey[0], ssKey.size());
|
||||
|
||||
// Value
|
||||
CDataStream ssValue(SER_DISK);
|
||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||
ssValue.reserve(10000);
|
||||
ssValue << value;
|
||||
Dbt datValue(&ssValue[0], ssValue.size());
|
||||
|
||||
// Write
|
||||
int ret = pdb->put(GetTxn(), &datKey, &datValue, (fOverwrite ? 0 : DB_NOOVERWRITE));
|
||||
int ret = pdb->put(activeTxn, &datKey, &datValue, (fOverwrite ? 0 : DB_NOOVERWRITE));
|
||||
|
||||
// Clear memory in case it was a private key
|
||||
memset(datKey.get_data(), 0, datKey.get_size());
|
||||
@@ -119,13 +183,13 @@ protected:
|
||||
assert(!"Erase called on database in read-only mode");
|
||||
|
||||
// Key
|
||||
CDataStream ssKey(SER_DISK);
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(1000);
|
||||
ssKey << key;
|
||||
Dbt datKey(&ssKey[0], ssKey.size());
|
||||
|
||||
// Erase
|
||||
int ret = pdb->del(GetTxn(), &datKey, 0);
|
||||
int ret = pdb->del(activeTxn, &datKey, 0);
|
||||
|
||||
// Clear memory
|
||||
memset(datKey.get_data(), 0, datKey.get_size());
|
||||
@@ -139,13 +203,13 @@ protected:
|
||||
return false;
|
||||
|
||||
// Key
|
||||
CDataStream ssKey(SER_DISK);
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(1000);
|
||||
ssKey << key;
|
||||
Dbt datKey(&ssKey[0], ssKey.size());
|
||||
|
||||
// Exists
|
||||
int ret = pdb->exists(GetTxn(), &datKey, 0);
|
||||
int ret = pdb->exists(activeTxn, &datKey, 0);
|
||||
|
||||
// Clear memory
|
||||
memset(datKey.get_data(), 0, datKey.get_size());
|
||||
@@ -202,46 +266,33 @@ protected:
|
||||
return 0;
|
||||
}
|
||||
|
||||
DbTxn* GetTxn()
|
||||
{
|
||||
if (!vTxn.empty())
|
||||
return vTxn.back();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
bool TxnBegin()
|
||||
{
|
||||
if (!pdb)
|
||||
if (!pdb || activeTxn)
|
||||
return false;
|
||||
DbTxn* ptxn = NULL;
|
||||
int ret = dbenv.txn_begin(GetTxn(), &ptxn, DB_TXN_NOSYNC);
|
||||
if (!ptxn || ret != 0)
|
||||
DbTxn* ptxn = bitdb.TxnBegin();
|
||||
if (!ptxn)
|
||||
return false;
|
||||
vTxn.push_back(ptxn);
|
||||
activeTxn = ptxn;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TxnCommit()
|
||||
{
|
||||
if (!pdb)
|
||||
if (!pdb || !activeTxn)
|
||||
return false;
|
||||
if (vTxn.empty())
|
||||
return false;
|
||||
int ret = vTxn.back()->commit(0);
|
||||
vTxn.pop_back();
|
||||
int ret = activeTxn->commit(0);
|
||||
activeTxn = NULL;
|
||||
return (ret == 0);
|
||||
}
|
||||
|
||||
bool TxnAbort()
|
||||
{
|
||||
if (!pdb)
|
||||
if (!pdb || !activeTxn)
|
||||
return false;
|
||||
if (vTxn.empty())
|
||||
return false;
|
||||
int ret = vTxn.back()->abort();
|
||||
vTxn.pop_back();
|
||||
int ret = activeTxn->abort();
|
||||
activeTxn = NULL;
|
||||
return (ret == 0);
|
||||
}
|
||||
|
||||
@@ -265,7 +316,7 @@ public:
|
||||
|
||||
|
||||
|
||||
|
||||
/** Access to the transaction database (blkindex.dat) */
|
||||
class CTxDB : public CDB
|
||||
{
|
||||
public:
|
||||
@@ -279,231 +330,32 @@ public:
|
||||
bool AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight);
|
||||
bool EraseTxIndex(const CTransaction& tx);
|
||||
bool ContainsTx(uint256 hash);
|
||||
bool ReadOwnerTxes(uint160 hash160, int nHeight, std::vector<CTransaction>& vtx);
|
||||
bool ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex);
|
||||
bool ReadDiskTx(uint256 hash, CTransaction& tx);
|
||||
bool ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex);
|
||||
bool ReadDiskTx(COutPoint outpoint, CTransaction& tx);
|
||||
bool WriteBlockIndex(const CDiskBlockIndex& blockindex);
|
||||
bool EraseBlockIndex(uint256 hash);
|
||||
bool ReadHashBestChain(uint256& hashBestChain);
|
||||
bool WriteHashBestChain(uint256 hashBestChain);
|
||||
bool ReadBestInvalidWork(CBigNum& bnBestInvalidWork);
|
||||
bool WriteBestInvalidWork(CBigNum bnBestInvalidWork);
|
||||
bool LoadBlockIndex();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CAddrDB : public CDB
|
||||
{
|
||||
public:
|
||||
CAddrDB(const char* pszMode="r+") : CDB("addr.dat", pszMode) { }
|
||||
private:
|
||||
CAddrDB(const CAddrDB&);
|
||||
void operator=(const CAddrDB&);
|
||||
public:
|
||||
bool WriteAddress(const CAddress& addr);
|
||||
bool EraseAddress(const CAddress& addr);
|
||||
bool LoadAddresses();
|
||||
};
|
||||
|
||||
bool LoadAddresses();
|
||||
|
||||
|
||||
|
||||
class CKeyPool
|
||||
{
|
||||
public:
|
||||
int64 nTime;
|
||||
std::vector<unsigned char> vchPubKey;
|
||||
|
||||
CKeyPool()
|
||||
{
|
||||
nTime = GetTime();
|
||||
}
|
||||
|
||||
CKeyPool(const std::vector<unsigned char>& vchPubKeyIn)
|
||||
{
|
||||
nTime = GetTime();
|
||||
vchPubKey = vchPubKeyIn;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(
|
||||
if (!(nType & SER_GETHASH))
|
||||
READWRITE(nVersion);
|
||||
READWRITE(nTime);
|
||||
READWRITE(vchPubKey);
|
||||
)
|
||||
bool LoadBlockIndexGuts();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
enum DBErrors
|
||||
/** Access to the (IP) address database (peers.dat) */
|
||||
class CAddrDB
|
||||
{
|
||||
DB_LOAD_OK,
|
||||
DB_CORRUPT,
|
||||
DB_TOO_NEW,
|
||||
DB_LOAD_FAIL,
|
||||
DB_NEED_REWRITE
|
||||
};
|
||||
|
||||
class CWalletDB : public CDB
|
||||
{
|
||||
public:
|
||||
CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
|
||||
{
|
||||
}
|
||||
private:
|
||||
CWalletDB(const CWalletDB&);
|
||||
void operator=(const CWalletDB&);
|
||||
boost::filesystem::path pathAddr;
|
||||
public:
|
||||
bool ReadName(const std::string& strAddress, std::string& strName)
|
||||
{
|
||||
strName = "";
|
||||
return Read(std::make_pair(std::string("name"), strAddress), strName);
|
||||
}
|
||||
|
||||
bool WriteName(const std::string& strAddress, const std::string& strName);
|
||||
|
||||
bool EraseName(const std::string& strAddress);
|
||||
|
||||
bool ReadTx(uint256 hash, CWalletTx& wtx)
|
||||
{
|
||||
return Read(std::make_pair(std::string("tx"), hash), wtx);
|
||||
}
|
||||
|
||||
bool WriteTx(uint256 hash, const CWalletTx& wtx)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::make_pair(std::string("tx"), hash), wtx);
|
||||
}
|
||||
|
||||
bool EraseTx(uint256 hash)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Erase(std::make_pair(std::string("tx"), hash));
|
||||
}
|
||||
|
||||
bool ReadKey(const std::vector<unsigned char>& vchPubKey, CPrivKey& vchPrivKey)
|
||||
{
|
||||
vchPrivKey.clear();
|
||||
return Read(std::make_pair(std::string("key"), vchPubKey), vchPrivKey);
|
||||
}
|
||||
|
||||
bool WriteKey(const std::vector<unsigned char>& vchPubKey, const CPrivKey& vchPrivKey)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false);
|
||||
}
|
||||
|
||||
bool WriteCryptedKey(const std::vector<unsigned char>& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, bool fEraseUnencryptedKey = true)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false))
|
||||
return false;
|
||||
if (fEraseUnencryptedKey)
|
||||
{
|
||||
Erase(std::make_pair(std::string("key"), vchPubKey));
|
||||
Erase(std::make_pair(std::string("wkey"), vchPubKey));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
|
||||
}
|
||||
|
||||
// Support for BIP 0013 : see https://en.bitcoin.it/wiki/BIP_0013
|
||||
bool ReadCScript(const uint160 &hash, CScript& redeemScript)
|
||||
{
|
||||
redeemScript.clear();
|
||||
return Read(std::make_pair(std::string("cscript"), hash), redeemScript);
|
||||
}
|
||||
|
||||
bool WriteCScript(const uint160& hash, const CScript& redeemScript)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
|
||||
}
|
||||
|
||||
bool WriteBestBlock(const CBlockLocator& locator)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::string("bestblock"), locator);
|
||||
}
|
||||
|
||||
bool ReadBestBlock(CBlockLocator& locator)
|
||||
{
|
||||
return Read(std::string("bestblock"), locator);
|
||||
}
|
||||
|
||||
bool ReadDefaultKey(std::vector<unsigned char>& vchPubKey)
|
||||
{
|
||||
vchPubKey.clear();
|
||||
return Read(std::string("defaultkey"), vchPubKey);
|
||||
}
|
||||
|
||||
bool WriteDefaultKey(const std::vector<unsigned char>& vchPubKey)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::string("defaultkey"), vchPubKey);
|
||||
}
|
||||
|
||||
bool ReadPool(int64 nPool, CKeyPool& keypool)
|
||||
{
|
||||
return Read(std::make_pair(std::string("pool"), nPool), keypool);
|
||||
}
|
||||
|
||||
bool WritePool(int64 nPool, const CKeyPool& keypool)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::make_pair(std::string("pool"), nPool), keypool);
|
||||
}
|
||||
|
||||
bool ErasePool(int64 nPool)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Erase(std::make_pair(std::string("pool"), nPool));
|
||||
}
|
||||
|
||||
// Settings are no longer stored in wallet.dat; these are
|
||||
// used only for backwards compatibility:
|
||||
template<typename T>
|
||||
bool ReadSetting(const std::string& strKey, T& value)
|
||||
{
|
||||
return Read(std::make_pair(std::string("setting"), strKey), value);
|
||||
}
|
||||
template<typename T>
|
||||
bool WriteSetting(const std::string& strKey, const T& value)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::make_pair(std::string("setting"), strKey), value);
|
||||
}
|
||||
bool EraseSetting(const std::string& strKey)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Erase(std::make_pair(std::string("setting"), strKey));
|
||||
}
|
||||
|
||||
bool WriteMinVersion(int nVersion)
|
||||
{
|
||||
return Write(std::string("minversion"), nVersion);
|
||||
}
|
||||
|
||||
bool ReadAccount(const std::string& strAccount, CAccount& account);
|
||||
bool WriteAccount(const std::string& strAccount, const CAccount& account);
|
||||
bool WriteAccountingEntry(const CAccountingEntry& acentry);
|
||||
int64 GetAccountCreditDebit(const std::string& strAccount);
|
||||
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
|
||||
|
||||
int LoadWallet(CWallet* pwallet);
|
||||
CAddrDB();
|
||||
bool Write(const CAddrMan& addr);
|
||||
bool Read(CAddrMan& addr);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // BITCOIN_DB_H
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#pragma warning(disable:4804)
|
||||
#pragma warning(disable:4805)
|
||||
#pragma warning(disable:4717)
|
||||
#endif
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#ifdef _WIN32_IE
|
||||
#undef _WIN32_IE
|
||||
#endif
|
||||
#define _WIN32_IE 0x0400
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
|
||||
// Include boost/foreach here as it defines __STDC_LIMIT_MACROS on some systems.
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#if (defined(__unix__) || defined(unix)) && !defined(USG)
|
||||
#include <sys/param.h> // to get BSD define
|
||||
#endif
|
||||
#ifdef MAC_OSX
|
||||
#ifndef BSD
|
||||
#define BSD 1
|
||||
#endif
|
||||
#endif
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/ecdsa.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/ripemd.h>
|
||||
#include <db_cxx.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <mswsock.h>
|
||||
#include <shlobj.h>
|
||||
#include <shlwapi.h>
|
||||
#include <io.h>
|
||||
#include <process.h>
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef BSD
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "serialize.h"
|
||||
#include "uint256.h"
|
||||
#include "util.h"
|
||||
#include "bignum.h"
|
||||
#include "base58.h"
|
||||
#include "main.h"
|
||||
#ifdef QT_GUI
|
||||
#include "qtui.h"
|
||||
#else
|
||||
#include "noui.h"
|
||||
#endif
|
||||
1080
src/init.cpp
1080
src/init.cpp
File diff suppressed because it is too large
Load Diff
12
src/init.h
12
src/init.h
@@ -1,17 +1,17 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_INIT_H
|
||||
#define BITCOIN_INIT_H
|
||||
|
||||
#include "wallet.h"
|
||||
|
||||
extern CWallet* pwalletMain;
|
||||
|
||||
void StartShutdown();
|
||||
void Shutdown(void* parg);
|
||||
bool AppInit(int argc, char* argv[]);
|
||||
bool AppInit2(int argc, char* argv[]);
|
||||
|
||||
bool GetStartOnSystemStartup();
|
||||
bool SetStartOnSystemStartup(bool fAutoStart);
|
||||
bool AppInit2();
|
||||
std::string HelpMessage();
|
||||
|
||||
#endif
|
||||
|
||||
63
src/irc.cpp
63
src/irc.cpp
@@ -1,18 +1,17 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "headers.h"
|
||||
#include "irc.h"
|
||||
#include "net.h"
|
||||
#include "strlcpy.h"
|
||||
#include "base58.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
int nGotIRCAddresses = 0;
|
||||
bool fGotExternalIP = false;
|
||||
|
||||
void ThreadIRCSeed2(void* parg);
|
||||
|
||||
@@ -108,13 +107,13 @@ int RecvUntil(SOCKET hSocket, const char* psz1, const char* psz2=NULL, const cha
|
||||
if (!RecvLineIRC(hSocket, strLine))
|
||||
return 0;
|
||||
printf("IRC %s\n", strLine.c_str());
|
||||
if (psz1 && strLine.find(psz1) != -1)
|
||||
if (psz1 && strLine.find(psz1) != string::npos)
|
||||
return 1;
|
||||
if (psz2 && strLine.find(psz2) != -1)
|
||||
if (psz2 && strLine.find(psz2) != string::npos)
|
||||
return 2;
|
||||
if (psz3 && strLine.find(psz3) != -1)
|
||||
if (psz3 && strLine.find(psz3) != string::npos)
|
||||
return 3;
|
||||
if (psz4 && strLine.find(psz4) != -1)
|
||||
if (psz4 && strLine.find(psz4) != string::npos)
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
@@ -177,8 +176,6 @@ bool GetIPFromIRC(SOCKET hSocket, string strMyName, CNetAddr& ipRet)
|
||||
// Hybrid IRC used by lfnet always returns IP when you userhost yourself,
|
||||
// but in case another IRC is ever used this should work.
|
||||
printf("GetIPFromIRC() got userhost %s\n", strHost.c_str());
|
||||
if (fUseProxy)
|
||||
return false;
|
||||
CNetAddr addr(strHost, true);
|
||||
if (!addr.IsValid())
|
||||
return false;
|
||||
@@ -191,7 +188,9 @@ bool GetIPFromIRC(SOCKET hSocket, string strMyName, CNetAddr& ipRet)
|
||||
|
||||
void ThreadIRCSeed(void* parg)
|
||||
{
|
||||
IMPLEMENT_RANDOMIZE_STACK(ThreadIRCSeed(parg));
|
||||
// Make this thread recognisable as the IRC seeding thread
|
||||
RenameThread("bitcoin-ircseed");
|
||||
|
||||
try
|
||||
{
|
||||
ThreadIRCSeed2(parg);
|
||||
@@ -201,22 +200,27 @@ void ThreadIRCSeed(void* parg)
|
||||
} catch (...) {
|
||||
PrintExceptionContinue(NULL, "ThreadIRCSeed()");
|
||||
}
|
||||
printf("ThreadIRCSeed exiting\n");
|
||||
printf("ThreadIRCSeed exited\n");
|
||||
}
|
||||
|
||||
void ThreadIRCSeed2(void* parg)
|
||||
{
|
||||
/* Dont advertise on IRC if we don't allow incoming connections */
|
||||
if (mapArgs.count("-connect") || fNoListen)
|
||||
// Don't connect to IRC if we won't use IPv4 connections.
|
||||
if (IsLimited(NET_IPV4))
|
||||
return;
|
||||
|
||||
// ... or if we won't make outbound connections and won't accept inbound ones.
|
||||
if (mapArgs.count("-connect") && fNoListen)
|
||||
return;
|
||||
|
||||
// ... or if IRC is not enabled.
|
||||
if (!GetBoolArg("-irc", false))
|
||||
return;
|
||||
|
||||
printf("ThreadIRCSeed started\n");
|
||||
int nErrorWait = 10;
|
||||
int nRetryWait = 10;
|
||||
bool fNameInUse = false;
|
||||
int nNameRetry = 0;
|
||||
|
||||
while (!fShutdown)
|
||||
{
|
||||
@@ -248,11 +252,15 @@ void ThreadIRCSeed2(void* parg)
|
||||
return;
|
||||
}
|
||||
|
||||
CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses
|
||||
CService addrLocal;
|
||||
string strMyName;
|
||||
if (addrLocalHost.IsRoutable() && !fUseProxy && !fNameInUse)
|
||||
strMyName = EncodeAddress(addrLocalHost);
|
||||
else
|
||||
strMyName = strprintf("x%u", GetRand(1000000000));
|
||||
// Don't use our IP as our nick if we're not listening
|
||||
// or if it keeps failing because the nick is already in use.
|
||||
if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3)
|
||||
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
|
||||
if (strMyName == "")
|
||||
strMyName = strprintf("x%"PRI64u"", GetRand(1000000000));
|
||||
|
||||
Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
|
||||
Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str());
|
||||
@@ -265,7 +273,7 @@ void ThreadIRCSeed2(void* parg)
|
||||
if (nRet == 2)
|
||||
{
|
||||
printf("IRC name already in use\n");
|
||||
fNameInUse = true;
|
||||
nNameRetry++;
|
||||
Wait(10);
|
||||
continue;
|
||||
}
|
||||
@@ -275,6 +283,7 @@ void ThreadIRCSeed2(void* parg)
|
||||
else
|
||||
return;
|
||||
}
|
||||
nNameRetry = 0;
|
||||
Sleep(500);
|
||||
|
||||
// Get our external IP from the IRC server and re-nick before joining the channel
|
||||
@@ -282,19 +291,19 @@ void ThreadIRCSeed2(void* parg)
|
||||
if (GetIPFromIRC(hSocket, strMyName, addrFromIRC))
|
||||
{
|
||||
printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str());
|
||||
if (!fUseProxy && addrFromIRC.IsRoutable())
|
||||
// Don't use our IP as our nick if we're not listening
|
||||
if (!fNoListen && addrFromIRC.IsRoutable())
|
||||
{
|
||||
// IRC lets you to re-nick
|
||||
fGotExternalIP = true;
|
||||
addrLocalHost.SetIP(addrFromIRC);
|
||||
strMyName = EncodeAddress(addrLocalHost);
|
||||
AddLocal(addrFromIRC, LOCAL_IRC);
|
||||
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
|
||||
Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (fTestNet) {
|
||||
Send(hSocket, "JOIN #bitcoinTEST\r");
|
||||
Send(hSocket, "WHO #bitcoinTEST\r");
|
||||
Send(hSocket, "JOIN #bitcoinTEST3\r");
|
||||
Send(hSocket, "WHO #bitcoinTEST3\r");
|
||||
} else {
|
||||
// randomly join #bitcoin00-#bitcoin99
|
||||
int channel_number = GetRandInt(100);
|
||||
@@ -341,7 +350,7 @@ void ThreadIRCSeed2(void* parg)
|
||||
if (DecodeAddress(pszName, addr))
|
||||
{
|
||||
addr.nTime = GetAdjustedTime();
|
||||
if (AddAddress(addr, 51 * 60))
|
||||
if (addrman.Add(addr, addrConnect, 51 * 60))
|
||||
printf("IRC got new address: %s\n", addr.ToString().c_str());
|
||||
nGotIRCAddresses++;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_IRC_H
|
||||
#define BITCOIN_IRC_H
|
||||
|
||||
void ThreadIRCSeed(void* parg);
|
||||
|
||||
extern int nGotIRCAddresses;
|
||||
extern bool fGotExternalIP;
|
||||
|
||||
#endif
|
||||
|
||||
295
src/key.cpp
295
src/key.cpp
@@ -1,9 +1,13 @@
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/ecdsa.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
|
||||
#include "key.h"
|
||||
|
||||
// Generate a private key from just the secret parameter
|
||||
int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
|
||||
@@ -44,7 +48,7 @@ err:
|
||||
|
||||
// Perform ECDSA key recovery (see SEC1 4.1.6) for curves over (mod p)-fields
|
||||
// recid selects which key is recovered
|
||||
// if check is nonzero, additional checks are performed
|
||||
// if check is non-zero, additional checks are performed
|
||||
int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned char *msg, int msglen, int recid, int check)
|
||||
{
|
||||
if (!eckey) return 0;
|
||||
@@ -115,3 +119,288 @@ err:
|
||||
if (Q != NULL) EC_POINT_free(Q);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CKey::SetCompressedPubKey()
|
||||
{
|
||||
EC_KEY_set_conv_form(pkey, POINT_CONVERSION_COMPRESSED);
|
||||
fCompressedPubKey = true;
|
||||
}
|
||||
|
||||
void CKey::Reset()
|
||||
{
|
||||
fCompressedPubKey = false;
|
||||
if (pkey != NULL)
|
||||
EC_KEY_free(pkey);
|
||||
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
|
||||
if (pkey == NULL)
|
||||
throw key_error("CKey::CKey() : EC_KEY_new_by_curve_name failed");
|
||||
fSet = false;
|
||||
}
|
||||
|
||||
CKey::CKey()
|
||||
{
|
||||
pkey = NULL;
|
||||
Reset();
|
||||
}
|
||||
|
||||
CKey::CKey(const CKey& b)
|
||||
{
|
||||
pkey = EC_KEY_dup(b.pkey);
|
||||
if (pkey == NULL)
|
||||
throw key_error("CKey::CKey(const CKey&) : EC_KEY_dup failed");
|
||||
fSet = b.fSet;
|
||||
}
|
||||
|
||||
CKey& CKey::operator=(const CKey& b)
|
||||
{
|
||||
if (!EC_KEY_copy(pkey, b.pkey))
|
||||
throw key_error("CKey::operator=(const CKey&) : EC_KEY_copy failed");
|
||||
fSet = b.fSet;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
CKey::~CKey()
|
||||
{
|
||||
EC_KEY_free(pkey);
|
||||
}
|
||||
|
||||
bool CKey::IsNull() const
|
||||
{
|
||||
return !fSet;
|
||||
}
|
||||
|
||||
bool CKey::IsCompressed() const
|
||||
{
|
||||
return fCompressedPubKey;
|
||||
}
|
||||
|
||||
void CKey::MakeNewKey(bool fCompressed)
|
||||
{
|
||||
if (!EC_KEY_generate_key(pkey))
|
||||
throw key_error("CKey::MakeNewKey() : EC_KEY_generate_key failed");
|
||||
if (fCompressed)
|
||||
SetCompressedPubKey();
|
||||
fSet = true;
|
||||
}
|
||||
|
||||
bool CKey::SetPrivKey(const CPrivKey& vchPrivKey)
|
||||
{
|
||||
const unsigned char* pbegin = &vchPrivKey[0];
|
||||
if (d2i_ECPrivateKey(&pkey, &pbegin, vchPrivKey.size()))
|
||||
{
|
||||
// In testing, d2i_ECPrivateKey can return true
|
||||
// but fill in pkey with a key that fails
|
||||
// EC_KEY_check_key, so:
|
||||
if (EC_KEY_check_key(pkey))
|
||||
{
|
||||
fSet = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// If vchPrivKey data is bad d2i_ECPrivateKey() can
|
||||
// leave pkey in a state where calling EC_KEY_free()
|
||||
// crashes. To avoid that, set pkey to NULL and
|
||||
// leak the memory (a leak is better than a crash)
|
||||
pkey = NULL;
|
||||
Reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CKey::SetSecret(const CSecret& vchSecret, bool fCompressed)
|
||||
{
|
||||
EC_KEY_free(pkey);
|
||||
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
|
||||
if (pkey == NULL)
|
||||
throw key_error("CKey::SetSecret() : EC_KEY_new_by_curve_name failed");
|
||||
if (vchSecret.size() != 32)
|
||||
throw key_error("CKey::SetSecret() : secret must be 32 bytes");
|
||||
BIGNUM *bn = BN_bin2bn(&vchSecret[0],32,BN_new());
|
||||
if (bn == NULL)
|
||||
throw key_error("CKey::SetSecret() : BN_bin2bn failed");
|
||||
if (!EC_KEY_regenerate_key(pkey,bn))
|
||||
{
|
||||
BN_clear_free(bn);
|
||||
throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
|
||||
}
|
||||
BN_clear_free(bn);
|
||||
fSet = true;
|
||||
if (fCompressed || fCompressedPubKey)
|
||||
SetCompressedPubKey();
|
||||
return true;
|
||||
}
|
||||
|
||||
CSecret CKey::GetSecret(bool &fCompressed) const
|
||||
{
|
||||
CSecret vchRet;
|
||||
vchRet.resize(32);
|
||||
const BIGNUM *bn = EC_KEY_get0_private_key(pkey);
|
||||
int nBytes = BN_num_bytes(bn);
|
||||
if (bn == NULL)
|
||||
throw key_error("CKey::GetSecret() : EC_KEY_get0_private_key failed");
|
||||
int n=BN_bn2bin(bn,&vchRet[32 - nBytes]);
|
||||
if (n != nBytes)
|
||||
throw key_error("CKey::GetSecret(): BN_bn2bin failed");
|
||||
fCompressed = fCompressedPubKey;
|
||||
return vchRet;
|
||||
}
|
||||
|
||||
CPrivKey CKey::GetPrivKey() const
|
||||
{
|
||||
int nSize = i2d_ECPrivateKey(pkey, NULL);
|
||||
if (!nSize)
|
||||
throw key_error("CKey::GetPrivKey() : i2d_ECPrivateKey failed");
|
||||
CPrivKey vchPrivKey(nSize, 0);
|
||||
unsigned char* pbegin = &vchPrivKey[0];
|
||||
if (i2d_ECPrivateKey(pkey, &pbegin) != nSize)
|
||||
throw key_error("CKey::GetPrivKey() : i2d_ECPrivateKey returned unexpected size");
|
||||
return vchPrivKey;
|
||||
}
|
||||
|
||||
bool CKey::SetPubKey(const CPubKey& vchPubKey)
|
||||
{
|
||||
const unsigned char* pbegin = &vchPubKey.vchPubKey[0];
|
||||
if (o2i_ECPublicKey(&pkey, &pbegin, vchPubKey.vchPubKey.size()))
|
||||
{
|
||||
fSet = true;
|
||||
if (vchPubKey.vchPubKey.size() == 33)
|
||||
SetCompressedPubKey();
|
||||
return true;
|
||||
}
|
||||
pkey = NULL;
|
||||
Reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
CPubKey CKey::GetPubKey() const
|
||||
{
|
||||
int nSize = i2o_ECPublicKey(pkey, NULL);
|
||||
if (!nSize)
|
||||
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey failed");
|
||||
std::vector<unsigned char> vchPubKey(nSize, 0);
|
||||
unsigned char* pbegin = &vchPubKey[0];
|
||||
if (i2o_ECPublicKey(pkey, &pbegin) != nSize)
|
||||
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey returned unexpected size");
|
||||
return CPubKey(vchPubKey);
|
||||
}
|
||||
|
||||
bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
unsigned int nSize = ECDSA_size(pkey);
|
||||
vchSig.resize(nSize); // Make sure it is big enough
|
||||
if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], &nSize, pkey))
|
||||
{
|
||||
vchSig.clear();
|
||||
return false;
|
||||
}
|
||||
vchSig.resize(nSize); // Shrink to fit actual size
|
||||
return true;
|
||||
}
|
||||
|
||||
// create a compact signature (65 bytes), which allows reconstructing the used public key
|
||||
// The format is one header byte, followed by two times 32 bytes for the serialized r and s values.
|
||||
// The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
|
||||
// 0x1D = second key with even y, 0x1E = second key with odd y
|
||||
bool CKey::SignCompact(uint256 hash, std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
bool fOk = false;
|
||||
ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey);
|
||||
if (sig==NULL)
|
||||
return false;
|
||||
vchSig.clear();
|
||||
vchSig.resize(65,0);
|
||||
int nBitsR = BN_num_bits(sig->r);
|
||||
int nBitsS = BN_num_bits(sig->s);
|
||||
if (nBitsR <= 256 && nBitsS <= 256)
|
||||
{
|
||||
int nRecId = -1;
|
||||
for (int i=0; i<4; i++)
|
||||
{
|
||||
CKey keyRec;
|
||||
keyRec.fSet = true;
|
||||
if (fCompressedPubKey)
|
||||
keyRec.SetCompressedPubKey();
|
||||
if (ECDSA_SIG_recover_key_GFp(keyRec.pkey, sig, (unsigned char*)&hash, sizeof(hash), i, 1) == 1)
|
||||
if (keyRec.GetPubKey() == this->GetPubKey())
|
||||
{
|
||||
nRecId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nRecId == -1)
|
||||
throw key_error("CKey::SignCompact() : unable to construct recoverable key");
|
||||
|
||||
vchSig[0] = nRecId+27+(fCompressedPubKey ? 4 : 0);
|
||||
BN_bn2bin(sig->r,&vchSig[33-(nBitsR+7)/8]);
|
||||
BN_bn2bin(sig->s,&vchSig[65-(nBitsS+7)/8]);
|
||||
fOk = true;
|
||||
}
|
||||
ECDSA_SIG_free(sig);
|
||||
return fOk;
|
||||
}
|
||||
|
||||
// reconstruct public key from a compact signature
|
||||
// This is only slightly more CPU intensive than just verifying it.
|
||||
// If this function succeeds, the recovered public key is guaranteed to be valid
|
||||
// (the signature is a valid signature of the given data for that key)
|
||||
bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
if (vchSig.size() != 65)
|
||||
return false;
|
||||
int nV = vchSig[0];
|
||||
if (nV<27 || nV>=35)
|
||||
return false;
|
||||
ECDSA_SIG *sig = ECDSA_SIG_new();
|
||||
BN_bin2bn(&vchSig[1],32,sig->r);
|
||||
BN_bin2bn(&vchSig[33],32,sig->s);
|
||||
|
||||
EC_KEY_free(pkey);
|
||||
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
|
||||
if (nV >= 31)
|
||||
{
|
||||
SetCompressedPubKey();
|
||||
nV -= 4;
|
||||
}
|
||||
if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), nV - 27, 0) == 1)
|
||||
{
|
||||
fSet = true;
|
||||
ECDSA_SIG_free(sig);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
// -1 = error, 0 = bad sig, 1 = good
|
||||
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CKey::VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
CKey key;
|
||||
if (!key.SetCompactSignature(hash, vchSig))
|
||||
return false;
|
||||
if (GetPubKey() != key.GetPubKey())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CKey::IsValid()
|
||||
{
|
||||
if (!fSet)
|
||||
return false;
|
||||
|
||||
if (!EC_KEY_check_key(pkey))
|
||||
return false;
|
||||
|
||||
bool fCompr;
|
||||
CSecret secret = GetSecret(fCompr);
|
||||
CKey key2;
|
||||
key2.SetSecret(secret, fCompr);
|
||||
return GetPubKey() == key2.GetPubKey();
|
||||
}
|
||||
|
||||
329
src/key.h
329
src/key.h
@@ -1,19 +1,19 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_KEY_H
|
||||
#define BITCOIN_KEY_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/ecdsa.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
|
||||
#include "allocators.h"
|
||||
#include "serialize.h"
|
||||
#include "uint256.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <openssl/ec.h> // for EC_KEY definition
|
||||
|
||||
// secp160k1
|
||||
// const unsigned int PRIVATE_KEY_SIZE = 192;
|
||||
@@ -38,22 +38,74 @@
|
||||
// see www.keylength.com
|
||||
// script supports up to 75 for single byte push
|
||||
|
||||
int extern EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key);
|
||||
int extern ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned char *msg, int msglen, int recid, int check);
|
||||
|
||||
class key_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit key_error(const std::string& str) : std::runtime_error(str) {}
|
||||
};
|
||||
|
||||
/** A reference to a CKey: the Hash160 of its serialized public key */
|
||||
class CKeyID : public uint160
|
||||
{
|
||||
public:
|
||||
CKeyID() : uint160(0) { }
|
||||
CKeyID(const uint160 &in) : uint160(in) { }
|
||||
};
|
||||
|
||||
// secure_allocator is defined in serialize.h
|
||||
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
|
||||
class CScriptID : public uint160
|
||||
{
|
||||
public:
|
||||
CScriptID() : uint160(0) { }
|
||||
CScriptID(const uint160 &in) : uint160(in) { }
|
||||
};
|
||||
|
||||
/** An encapsulated public key. */
|
||||
class CPubKey {
|
||||
private:
|
||||
std::vector<unsigned char> vchPubKey;
|
||||
friend class CKey;
|
||||
|
||||
public:
|
||||
CPubKey() { }
|
||||
CPubKey(const std::vector<unsigned char> &vchPubKeyIn) : vchPubKey(vchPubKeyIn) { }
|
||||
friend bool operator==(const CPubKey &a, const CPubKey &b) { return a.vchPubKey == b.vchPubKey; }
|
||||
friend bool operator!=(const CPubKey &a, const CPubKey &b) { return a.vchPubKey != b.vchPubKey; }
|
||||
friend bool operator<(const CPubKey &a, const CPubKey &b) { return a.vchPubKey < b.vchPubKey; }
|
||||
|
||||
IMPLEMENT_SERIALIZE(
|
||||
READWRITE(vchPubKey);
|
||||
)
|
||||
|
||||
CKeyID GetID() const {
|
||||
return CKeyID(Hash160(vchPubKey));
|
||||
}
|
||||
|
||||
uint256 GetHash() const {
|
||||
return Hash(vchPubKey.begin(), vchPubKey.end());
|
||||
}
|
||||
|
||||
bool IsValid() const {
|
||||
return vchPubKey.size() == 33 || vchPubKey.size() == 65;
|
||||
}
|
||||
|
||||
bool IsCompressed() const {
|
||||
return vchPubKey.size() == 33;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> Raw() const {
|
||||
return vchPubKey;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// secure_allocator is defined in allocators.h
|
||||
// CPrivKey is a serialized private key, with all parameters included (279 bytes)
|
||||
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
|
||||
// CSecret is a serialization of just the secret parameter (32 bytes)
|
||||
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CSecret;
|
||||
|
||||
/** An encapsulated OpenSSL Elliptic Curve key (public and/or private) */
|
||||
class CKey
|
||||
{
|
||||
protected:
|
||||
@@ -61,267 +113,50 @@ protected:
|
||||
bool fSet;
|
||||
bool fCompressedPubKey;
|
||||
|
||||
void SetCompressedPubKey()
|
||||
{
|
||||
EC_KEY_set_conv_form(pkey, POINT_CONVERSION_COMPRESSED);
|
||||
fCompressedPubKey = true;
|
||||
}
|
||||
void SetCompressedPubKey();
|
||||
|
||||
public:
|
||||
|
||||
void Reset()
|
||||
{
|
||||
fCompressedPubKey = false;
|
||||
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
|
||||
if (pkey == NULL)
|
||||
throw key_error("CKey::CKey() : EC_KEY_new_by_curve_name failed");
|
||||
fSet = false;
|
||||
}
|
||||
void Reset();
|
||||
|
||||
CKey()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
CKey();
|
||||
CKey(const CKey& b);
|
||||
|
||||
CKey(const CKey& b)
|
||||
{
|
||||
pkey = EC_KEY_dup(b.pkey);
|
||||
if (pkey == NULL)
|
||||
throw key_error("CKey::CKey(const CKey&) : EC_KEY_dup failed");
|
||||
fSet = b.fSet;
|
||||
}
|
||||
CKey& operator=(const CKey& b);
|
||||
|
||||
CKey& operator=(const CKey& b)
|
||||
{
|
||||
if (!EC_KEY_copy(pkey, b.pkey))
|
||||
throw key_error("CKey::operator=(const CKey&) : EC_KEY_copy failed");
|
||||
fSet = b.fSet;
|
||||
return (*this);
|
||||
}
|
||||
~CKey();
|
||||
|
||||
~CKey()
|
||||
{
|
||||
EC_KEY_free(pkey);
|
||||
}
|
||||
bool IsNull() const;
|
||||
bool IsCompressed() const;
|
||||
|
||||
bool IsNull() const
|
||||
{
|
||||
return !fSet;
|
||||
}
|
||||
void MakeNewKey(bool fCompressed);
|
||||
bool SetPrivKey(const CPrivKey& vchPrivKey);
|
||||
bool SetSecret(const CSecret& vchSecret, bool fCompressed = false);
|
||||
CSecret GetSecret(bool &fCompressed) const;
|
||||
CPrivKey GetPrivKey() const;
|
||||
bool SetPubKey(const CPubKey& vchPubKey);
|
||||
CPubKey GetPubKey() const;
|
||||
|
||||
bool IsCompressed() const
|
||||
{
|
||||
return fCompressedPubKey;
|
||||
}
|
||||
|
||||
void MakeNewKey(bool fCompressed)
|
||||
{
|
||||
if (!EC_KEY_generate_key(pkey))
|
||||
throw key_error("CKey::MakeNewKey() : EC_KEY_generate_key failed");
|
||||
if (fCompressed)
|
||||
SetCompressedPubKey();
|
||||
fSet = true;
|
||||
}
|
||||
|
||||
bool SetPrivKey(const CPrivKey& vchPrivKey)
|
||||
{
|
||||
const unsigned char* pbegin = &vchPrivKey[0];
|
||||
if (!d2i_ECPrivateKey(&pkey, &pbegin, vchPrivKey.size()))
|
||||
return false;
|
||||
fSet = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetSecret(const CSecret& vchSecret, bool fCompressed = false)
|
||||
{
|
||||
EC_KEY_free(pkey);
|
||||
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
|
||||
if (pkey == NULL)
|
||||
throw key_error("CKey::SetSecret() : EC_KEY_new_by_curve_name failed");
|
||||
if (vchSecret.size() != 32)
|
||||
throw key_error("CKey::SetSecret() : secret must be 32 bytes");
|
||||
BIGNUM *bn = BN_bin2bn(&vchSecret[0],32,BN_new());
|
||||
if (bn == NULL)
|
||||
throw key_error("CKey::SetSecret() : BN_bin2bn failed");
|
||||
if (!EC_KEY_regenerate_key(pkey,bn))
|
||||
{
|
||||
BN_clear_free(bn);
|
||||
throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
|
||||
}
|
||||
BN_clear_free(bn);
|
||||
fSet = true;
|
||||
if (fCompressed || fCompressedPubKey)
|
||||
SetCompressedPubKey();
|
||||
return true;
|
||||
}
|
||||
|
||||
CSecret GetSecret(bool &fCompressed) const
|
||||
{
|
||||
CSecret vchRet;
|
||||
vchRet.resize(32);
|
||||
const BIGNUM *bn = EC_KEY_get0_private_key(pkey);
|
||||
int nBytes = BN_num_bytes(bn);
|
||||
if (bn == NULL)
|
||||
throw key_error("CKey::GetSecret() : EC_KEY_get0_private_key failed");
|
||||
int n=BN_bn2bin(bn,&vchRet[32 - nBytes]);
|
||||
if (n != nBytes)
|
||||
throw key_error("CKey::GetSecret(): BN_bn2bin failed");
|
||||
fCompressed = fCompressedPubKey;
|
||||
return vchRet;
|
||||
}
|
||||
|
||||
CPrivKey GetPrivKey() const
|
||||
{
|
||||
unsigned int nSize = i2d_ECPrivateKey(pkey, NULL);
|
||||
if (!nSize)
|
||||
throw key_error("CKey::GetPrivKey() : i2d_ECPrivateKey failed");
|
||||
CPrivKey vchPrivKey(nSize, 0);
|
||||
unsigned char* pbegin = &vchPrivKey[0];
|
||||
if (i2d_ECPrivateKey(pkey, &pbegin) != nSize)
|
||||
throw key_error("CKey::GetPrivKey() : i2d_ECPrivateKey returned unexpected size");
|
||||
return vchPrivKey;
|
||||
}
|
||||
|
||||
bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
|
||||
{
|
||||
const unsigned char* pbegin = &vchPubKey[0];
|
||||
if (!o2i_ECPublicKey(&pkey, &pbegin, vchPubKey.size()))
|
||||
return false;
|
||||
fSet = true;
|
||||
if (vchPubKey.size() == 33)
|
||||
SetCompressedPubKey();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> GetPubKey() const
|
||||
{
|
||||
unsigned int nSize = i2o_ECPublicKey(pkey, NULL);
|
||||
if (!nSize)
|
||||
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey failed");
|
||||
std::vector<unsigned char> vchPubKey(nSize, 0);
|
||||
unsigned char* pbegin = &vchPubKey[0];
|
||||
if (i2o_ECPublicKey(pkey, &pbegin) != nSize)
|
||||
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey returned unexpected size");
|
||||
return vchPubKey;
|
||||
}
|
||||
|
||||
bool Sign(uint256 hash, std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
unsigned int nSize = ECDSA_size(pkey);
|
||||
vchSig.resize(nSize); // Make sure it is big enough
|
||||
if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], &nSize, pkey))
|
||||
{
|
||||
vchSig.clear();
|
||||
return false;
|
||||
}
|
||||
vchSig.resize(nSize); // Shrink to fit actual size
|
||||
return true;
|
||||
}
|
||||
bool Sign(uint256 hash, std::vector<unsigned char>& vchSig);
|
||||
|
||||
// create a compact signature (65 bytes), which allows reconstructing the used public key
|
||||
// The format is one header byte, followed by two times 32 bytes for the serialized r and s values.
|
||||
// The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
|
||||
// 0x1D = second key with even y, 0x1E = second key with odd y
|
||||
bool SignCompact(uint256 hash, std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
bool fOk = false;
|
||||
ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey);
|
||||
if (sig==NULL)
|
||||
return false;
|
||||
vchSig.clear();
|
||||
vchSig.resize(65,0);
|
||||
int nBitsR = BN_num_bits(sig->r);
|
||||
int nBitsS = BN_num_bits(sig->s);
|
||||
if (nBitsR <= 256 && nBitsS <= 256)
|
||||
{
|
||||
int nRecId = -1;
|
||||
for (int i=0; i<4; i++)
|
||||
{
|
||||
CKey keyRec;
|
||||
keyRec.fSet = true;
|
||||
if (fCompressedPubKey)
|
||||
keyRec.SetCompressedPubKey();
|
||||
if (ECDSA_SIG_recover_key_GFp(keyRec.pkey, sig, (unsigned char*)&hash, sizeof(hash), i, 1) == 1)
|
||||
if (keyRec.GetPubKey() == this->GetPubKey())
|
||||
{
|
||||
nRecId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nRecId == -1)
|
||||
throw key_error("CKey::SignCompact() : unable to construct recoverable key");
|
||||
|
||||
vchSig[0] = nRecId+27+(fCompressedPubKey ? 4 : 0);
|
||||
BN_bn2bin(sig->r,&vchSig[33-(nBitsR+7)/8]);
|
||||
BN_bn2bin(sig->s,&vchSig[65-(nBitsS+7)/8]);
|
||||
fOk = true;
|
||||
}
|
||||
ECDSA_SIG_free(sig);
|
||||
return fOk;
|
||||
}
|
||||
bool SignCompact(uint256 hash, std::vector<unsigned char>& vchSig);
|
||||
|
||||
// reconstruct public key from a compact signature
|
||||
// This is only slightly more CPU intensive than just verifying it.
|
||||
// If this function succeeds, the recovered public key is guaranteed to be valid
|
||||
// (the signature is a valid signature of the given data for that key)
|
||||
bool SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
if (vchSig.size() != 65)
|
||||
return false;
|
||||
int nV = vchSig[0];
|
||||
if (nV<27 || nV>=35)
|
||||
return false;
|
||||
ECDSA_SIG *sig = ECDSA_SIG_new();
|
||||
BN_bin2bn(&vchSig[1],32,sig->r);
|
||||
BN_bin2bn(&vchSig[33],32,sig->s);
|
||||
bool SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig);
|
||||
|
||||
EC_KEY_free(pkey);
|
||||
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
|
||||
if (nV >= 31)
|
||||
{
|
||||
SetCompressedPubKey();
|
||||
nV -= 4;
|
||||
}
|
||||
if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), nV - 27, 0) == 1)
|
||||
{
|
||||
fSet = true;
|
||||
ECDSA_SIG_free(sig);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
// -1 = error, 0 = bad sig, 1 = good
|
||||
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool Verify(uint256 hash, const std::vector<unsigned char>& vchSig);
|
||||
|
||||
// Verify a compact signature
|
||||
bool VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig)
|
||||
{
|
||||
CKey key;
|
||||
if (!key.SetCompactSignature(hash, vchSig))
|
||||
return false;
|
||||
if (GetPubKey() != key.GetPubKey())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig);
|
||||
|
||||
bool IsValid()
|
||||
{
|
||||
if (!fSet)
|
||||
return false;
|
||||
|
||||
bool fCompr;
|
||||
CSecret secret = GetSecret(fCompr);
|
||||
CKey key2;
|
||||
key2.SetSecret(secret, fCompr);
|
||||
return GetPubKey() == key2.GetPubKey();
|
||||
}
|
||||
bool IsValid();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "headers.h"
|
||||
#include "crypter.h"
|
||||
#include "db.h"
|
||||
#include "keystore.h"
|
||||
#include "script.h"
|
||||
|
||||
bool CKeyStore::GetPubKey(const CBitcoinAddress &address, std::vector<unsigned char> &vchPubKeyOut) const
|
||||
bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
|
||||
{
|
||||
CKey key;
|
||||
if (!GetKey(address, key))
|
||||
@@ -21,31 +19,37 @@ bool CBasicKeyStore::AddKey(const CKey& key)
|
||||
{
|
||||
bool fCompressed = false;
|
||||
CSecret secret = key.GetSecret(fCompressed);
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
mapKeys[CBitcoinAddress(key.GetPubKey())] = make_pair(secret, fCompressed);
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
mapKeys[key.GetPubKey().GetID()] = make_pair(secret, fCompressed);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
mapScripts[Hash160(redeemScript)] = redeemScript;
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
mapScripts[redeemScript.GetID()] = redeemScript;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBasicKeyStore::HaveCScript(const uint160& hash) const
|
||||
bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
|
||||
{
|
||||
bool result;
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
result = (mapScripts.count(hash) > 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool CBasicKeyStore::GetCScript(const uint160 &hash, CScript& redeemScriptOut) const
|
||||
bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
ScriptMap::const_iterator mi = mapScripts.find(hash);
|
||||
if (mi != mapScripts.end())
|
||||
{
|
||||
@@ -58,8 +62,8 @@ bool CBasicKeyStore::GetCScript(const uint160 &hash, CScript& redeemScriptOut) c
|
||||
|
||||
bool CCryptoKeyStore::SetCrypted()
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (fUseCrypto)
|
||||
return true;
|
||||
if (!mapKeys.empty())
|
||||
@@ -69,20 +73,36 @@ bool CCryptoKeyStore::SetCrypted()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCryptoKeyStore::Lock()
|
||||
{
|
||||
if (!SetCrypted())
|
||||
return false;
|
||||
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
vMasterKey.clear();
|
||||
}
|
||||
|
||||
NotifyStatusChanged(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!SetCrypted())
|
||||
return false;
|
||||
|
||||
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
|
||||
for (; mi != mapCryptedKeys.end(); ++mi)
|
||||
{
|
||||
const std::vector<unsigned char> &vchPubKey = (*mi).second.first;
|
||||
const CPubKey &vchPubKey = (*mi).second.first;
|
||||
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
|
||||
CSecret vchSecret;
|
||||
if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, Hash(vchPubKey.begin(), vchPubKey.end()), vchSecret))
|
||||
if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
|
||||
return false;
|
||||
if (vchSecret.size() != 32)
|
||||
return false;
|
||||
CKey key;
|
||||
key.SetPubKey(vchPubKey);
|
||||
@@ -93,13 +113,14 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
|
||||
}
|
||||
vMasterKey = vMasterKeyIn;
|
||||
}
|
||||
NotifyStatusChanged(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCryptoKeyStore::AddKey(const CKey& key)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::AddKey(key);
|
||||
|
||||
@@ -107,9 +128,9 @@ bool CCryptoKeyStore::AddKey(const CKey& key)
|
||||
return false;
|
||||
|
||||
std::vector<unsigned char> vchCryptedSecret;
|
||||
std::vector<unsigned char> vchPubKey = key.GetPubKey();
|
||||
CPubKey vchPubKey = key.GetPubKey();
|
||||
bool fCompressed;
|
||||
if (!EncryptSecret(vMasterKey, key.GetSecret(fCompressed), Hash(vchPubKey.begin(), vchPubKey.end()), vchCryptedSecret))
|
||||
if (!EncryptSecret(vMasterKey, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))
|
||||
return false;
|
||||
|
||||
if (!AddCryptedKey(key.GetPubKey(), vchCryptedSecret))
|
||||
@@ -119,32 +140,34 @@ bool CCryptoKeyStore::AddKey(const CKey& key)
|
||||
}
|
||||
|
||||
|
||||
bool CCryptoKeyStore::AddCryptedKey(const std::vector<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
||||
bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!SetCrypted())
|
||||
return false;
|
||||
|
||||
mapCryptedKeys[CBitcoinAddress(vchPubKey)] = make_pair(vchPubKey, vchCryptedSecret);
|
||||
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCryptoKeyStore::GetKey(const CBitcoinAddress &address, CKey& keyOut) const
|
||||
bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::GetKey(address, keyOut);
|
||||
|
||||
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
|
||||
if (mi != mapCryptedKeys.end())
|
||||
{
|
||||
const std::vector<unsigned char> &vchPubKey = (*mi).second.first;
|
||||
const CPubKey &vchPubKey = (*mi).second.first;
|
||||
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
|
||||
CSecret vchSecret;
|
||||
if (!DecryptSecret(vMasterKey, vchCryptedSecret, Hash(vchPubKey.begin(), vchPubKey.end()), vchSecret))
|
||||
if (!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
|
||||
return false;
|
||||
if (vchSecret.size() != 32)
|
||||
return false;
|
||||
keyOut.SetPubKey(vchPubKey);
|
||||
keyOut.SetSecret(vchSecret);
|
||||
@@ -154,10 +177,10 @@ bool CCryptoKeyStore::GetKey(const CBitcoinAddress &address, CKey& keyOut) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCryptoKeyStore::GetPubKey(const CBitcoinAddress &address, std::vector<unsigned char>& vchPubKeyOut) const
|
||||
bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CKeyStore::GetPubKey(address, vchPubKeyOut);
|
||||
|
||||
@@ -173,8 +196,8 @@ bool CCryptoKeyStore::GetPubKey(const CBitcoinAddress &address, std::vector<unsi
|
||||
|
||||
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!mapCryptedKeys.empty() || IsCrypted())
|
||||
return false;
|
||||
|
||||
@@ -184,10 +207,10 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
||||
CKey key;
|
||||
if (!key.SetSecret(mKey.second.first, mKey.second.second))
|
||||
return false;
|
||||
const std::vector<unsigned char> vchPubKey = key.GetPubKey();
|
||||
const CPubKey vchPubKey = key.GetPubKey();
|
||||
std::vector<unsigned char> vchCryptedSecret;
|
||||
bool fCompressed;
|
||||
if (!EncryptSecret(vMasterKeyIn, key.GetSecret(fCompressed), Hash(vchPubKey.begin(), vchPubKey.end()), vchCryptedSecret))
|
||||
if (!EncryptSecret(vMasterKeyIn, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret))
|
||||
return false;
|
||||
if (!AddCryptedKey(vchPubKey, vchCryptedSecret))
|
||||
return false;
|
||||
|
||||
@@ -1,35 +1,40 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_KEYSTORE_H
|
||||
#define BITCOIN_KEYSTORE_H
|
||||
|
||||
#include "crypter.h"
|
||||
#include "script.h"
|
||||
#include "sync.h"
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
// A virtual base class for key stores
|
||||
class CScript;
|
||||
|
||||
/** A virtual base class for key stores */
|
||||
class CKeyStore
|
||||
{
|
||||
protected:
|
||||
mutable CCriticalSection cs_KeyStore;
|
||||
|
||||
public:
|
||||
virtual ~CKeyStore() {}
|
||||
|
||||
// Add a key to the store.
|
||||
virtual bool AddKey(const CKey& key) =0;
|
||||
|
||||
// Check whether a key corresponding to a given address is present in the store.
|
||||
virtual bool HaveKey(const CBitcoinAddress &address) const =0;
|
||||
virtual bool GetKey(const CBitcoinAddress &address, CKey& keyOut) const =0;
|
||||
virtual void GetKeys(std::set<CBitcoinAddress> &setAddress) const =0;
|
||||
virtual bool GetPubKey(const CBitcoinAddress &address, std::vector<unsigned char>& vchPubKeyOut) const;
|
||||
virtual bool HaveKey(const CKeyID &address) const =0;
|
||||
virtual bool GetKey(const CKeyID &address, CKey& keyOut) const =0;
|
||||
virtual void GetKeys(std::set<CKeyID> &setAddress) const =0;
|
||||
virtual bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
|
||||
|
||||
// Support for BIP 0013 : see https://en.bitcoin.it/wiki/BIP_0013
|
||||
virtual bool AddCScript(const CScript& redeemScript) =0;
|
||||
virtual bool HaveCScript(const uint160 &hash) const =0;
|
||||
virtual bool GetCScript(const uint160 &hash, CScript& redeemScriptOut) const =0;
|
||||
virtual bool HaveCScript(const CScriptID &hash) const =0;
|
||||
virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const =0;
|
||||
|
||||
virtual bool GetSecret(const CBitcoinAddress &address, CSecret& vchSecret, bool &fCompressed) const
|
||||
virtual bool GetSecret(const CKeyID &address, CSecret& vchSecret, bool &fCompressed) const
|
||||
{
|
||||
CKey key;
|
||||
if (!GetKey(address, key))
|
||||
@@ -39,10 +44,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<CBitcoinAddress, std::pair<CSecret, bool> > KeyMap;
|
||||
typedef std::map<uint160, CScript > ScriptMap;
|
||||
typedef std::map<CKeyID, std::pair<CSecret, bool> > KeyMap;
|
||||
typedef std::map<CScriptID, CScript > ScriptMap;
|
||||
|
||||
// Basic key store, that keeps keys in an address->secret map
|
||||
/** Basic key store, that keeps keys in an address->secret map */
|
||||
class CBasicKeyStore : public CKeyStore
|
||||
{
|
||||
protected:
|
||||
@@ -51,18 +56,20 @@ protected:
|
||||
|
||||
public:
|
||||
bool AddKey(const CKey& key);
|
||||
bool HaveKey(const CBitcoinAddress &address) const
|
||||
bool HaveKey(const CKeyID &address) const
|
||||
{
|
||||
bool result;
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
result = (mapKeys.count(address) > 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
void GetKeys(std::set<CBitcoinAddress> &setAddress) const
|
||||
void GetKeys(std::set<CKeyID> &setAddress) const
|
||||
{
|
||||
setAddress.clear();
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
KeyMap::const_iterator mi = mapKeys.begin();
|
||||
while (mi != mapKeys.end())
|
||||
{
|
||||
@@ -71,10 +78,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
bool GetKey(const CBitcoinAddress &address, CKey &keyOut) const
|
||||
bool GetKey(const CKeyID &address, CKey &keyOut) const
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
KeyMap::const_iterator mi = mapKeys.find(address);
|
||||
if (mi != mapKeys.end())
|
||||
{
|
||||
@@ -86,14 +93,15 @@ public:
|
||||
return false;
|
||||
}
|
||||
virtual bool AddCScript(const CScript& redeemScript);
|
||||
virtual bool HaveCScript(const uint160 &hash) const;
|
||||
virtual bool GetCScript(const uint160 &hash, CScript& redeemScriptOut) const;
|
||||
virtual bool HaveCScript(const CScriptID &hash) const;
|
||||
virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const;
|
||||
};
|
||||
|
||||
typedef std::map<CBitcoinAddress, std::pair<std::vector<unsigned char>, std::vector<unsigned char> > > CryptedKeyMap;
|
||||
typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
|
||||
|
||||
// Keystore which keeps the private keys encrypted
|
||||
// It derives from the basic key store, which is used if no encryption is active.
|
||||
/** Keystore which keeps the private keys encrypted.
|
||||
* It derives from the basic key store, which is used if no encryption is active.
|
||||
*/
|
||||
class CCryptoKeyStore : public CBasicKeyStore
|
||||
{
|
||||
private:
|
||||
@@ -128,37 +136,30 @@ public:
|
||||
if (!IsCrypted())
|
||||
return false;
|
||||
bool result;
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
result = vMasterKey.empty();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Lock()
|
||||
{
|
||||
if (!SetCrypted())
|
||||
return false;
|
||||
bool Lock();
|
||||
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
vMasterKey.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool AddCryptedKey(const std::vector<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
||||
virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
||||
bool AddKey(const CKey& key);
|
||||
bool HaveKey(const CBitcoinAddress &address) const
|
||||
bool HaveKey(const CKeyID &address) const
|
||||
{
|
||||
CRITICAL_BLOCK(cs_KeyStore)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::HaveKey(address);
|
||||
return mapCryptedKeys.count(address) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool GetKey(const CBitcoinAddress &address, CKey& keyOut) const;
|
||||
bool GetPubKey(const CBitcoinAddress &address, std::vector<unsigned char>& vchPubKeyOut) const;
|
||||
void GetKeys(std::set<CBitcoinAddress> &setAddress) const
|
||||
bool GetKey(const CKeyID &address, CKey& keyOut) const;
|
||||
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
|
||||
void GetKeys(std::set<CKeyID> &setAddress) const
|
||||
{
|
||||
if (!IsCrypted())
|
||||
{
|
||||
@@ -173,6 +174,11 @@ public:
|
||||
mi++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Wallet status (encrypted, locked) changed.
|
||||
* Note: Called without locks held.
|
||||
*/
|
||||
boost::signals2::signal<void (CCryptoKeyStore* wallet)> NotifyStatusChanged;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
1394
src/main.cpp
1394
src/main.cpp
File diff suppressed because it is too large
Load Diff
491
src/main.h
491
src/main.h
@@ -1,48 +1,40 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_MAIN_H
|
||||
#define BITCOIN_MAIN_H
|
||||
|
||||
#include "bignum.h"
|
||||
#include "sync.h"
|
||||
#include "net.h"
|
||||
#include "key.h"
|
||||
#include "script.h"
|
||||
#include "db.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
class CWallet;
|
||||
class CBlock;
|
||||
class CBlockIndex;
|
||||
class CWalletTx;
|
||||
class CWallet;
|
||||
class CKeyItem;
|
||||
class CReserveKey;
|
||||
class CWalletDB;
|
||||
|
||||
class CAddress;
|
||||
class CInv;
|
||||
class CRequestTracker;
|
||||
class CNode;
|
||||
|
||||
static const int CLIENT_VERSION = 60003;
|
||||
static const bool VERSION_IS_BETA = true;
|
||||
extern const std::string CLIENT_NAME;
|
||||
|
||||
static const unsigned int MAX_BLOCK_SIZE = 1000000;
|
||||
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
|
||||
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
|
||||
static const int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
|
||||
static const int64 COIN = 100000000;
|
||||
static const int64 CENT = 1000000;
|
||||
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
|
||||
static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
|
||||
static const unsigned int MAX_INV_SZ = 50000;
|
||||
static const int64 MIN_TX_FEE = 50000;
|
||||
static const int64 MIN_RELAY_TX_FEE = 10000;
|
||||
static const int64 MAX_MONEY = 21000000 * COIN;
|
||||
inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
|
||||
static const int COINBASE_MATURITY = 100;
|
||||
// Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp.
|
||||
static const int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
|
||||
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
|
||||
#ifdef USE_UPNP
|
||||
static const int fHaveUPnP = true;
|
||||
#else
|
||||
@@ -66,7 +58,6 @@ extern CBigNum bnBestChainWork;
|
||||
extern CBigNum bnBestInvalidWork;
|
||||
extern uint256 hashBestChain;
|
||||
extern CBlockIndex* pindexBest;
|
||||
extern uint64 nPooledTx;
|
||||
extern unsigned int nTransactionsUpdated;
|
||||
extern uint64 nLastBlockTx;
|
||||
extern uint64 nLastBlockSize;
|
||||
@@ -76,12 +67,13 @@ extern int64 nHPSTimerStart;
|
||||
extern int64 nTimeBestReceived;
|
||||
extern CCriticalSection cs_setpwalletRegistered;
|
||||
extern std::set<CWallet*> setpwalletRegistered;
|
||||
extern unsigned char pchMessageStart[4];
|
||||
|
||||
// Settings
|
||||
extern int64 nTransactionFee;
|
||||
|
||||
|
||||
|
||||
// Minimum disk space required - used in CheckDiskSpace()
|
||||
static const uint64 nMinDiskSpace = 52428800;
|
||||
|
||||
|
||||
class CReserveKey;
|
||||
@@ -90,14 +82,17 @@ class CTxIndex;
|
||||
|
||||
void RegisterWallet(CWallet* pwalletIn);
|
||||
void UnregisterWallet(CWallet* pwalletIn);
|
||||
void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false);
|
||||
bool ProcessBlock(CNode* pfrom, CBlock* pblock);
|
||||
bool CheckDiskSpace(uint64 nAdditionalBytes=0);
|
||||
FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode="rb");
|
||||
FILE* AppendBlockFile(unsigned int& nFileRet);
|
||||
bool LoadBlockIndex(bool fAllowNew=true);
|
||||
void PrintBlockTree();
|
||||
CBlockIndex* FindBlockByHeight(int nHeight);
|
||||
bool ProcessMessages(CNode* pfrom);
|
||||
bool SendMessages(CNode* pto, bool fSendTrickle);
|
||||
bool LoadExternalBlockFile(FILE* fileIn);
|
||||
void GenerateBitcoins(bool fGenerate, CWallet* pwallet);
|
||||
CBlock* CreateNewBlock(CReserveKey& reservekey);
|
||||
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
|
||||
@@ -108,7 +103,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
|
||||
int GetNumBlocksOfPeers();
|
||||
bool IsInitialBlockDownload();
|
||||
std::string GetWarnings(std::string strFor);
|
||||
|
||||
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock);
|
||||
|
||||
|
||||
|
||||
@@ -122,7 +117,7 @@ std::string GetWarnings(std::string strFor);
|
||||
|
||||
bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
|
||||
|
||||
|
||||
/** Position on disk for a particular transaction. */
|
||||
class CDiskTxPos
|
||||
{
|
||||
public:
|
||||
@@ -143,8 +138,8 @@ public:
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
|
||||
void SetNull() { nFile = -1; nBlockPos = 0; nTxPos = 0; }
|
||||
bool IsNull() const { return (nFile == -1); }
|
||||
void SetNull() { nFile = (unsigned int) -1; nBlockPos = 0; nTxPos = 0; }
|
||||
bool IsNull() const { return (nFile == (unsigned int) -1); }
|
||||
|
||||
friend bool operator==(const CDiskTxPos& a, const CDiskTxPos& b)
|
||||
{
|
||||
@@ -161,9 +156,9 @@ public:
|
||||
std::string ToString() const
|
||||
{
|
||||
if (IsNull())
|
||||
return strprintf("null");
|
||||
return "null";
|
||||
else
|
||||
return strprintf("(nFile=%d, nBlockPos=%d, nTxPos=%d)", nFile, nBlockPos, nTxPos);
|
||||
return strprintf("(nFile=%u, nBlockPos=%u, nTxPos=%u)", nFile, nBlockPos, nTxPos);
|
||||
}
|
||||
|
||||
void print() const
|
||||
@@ -174,7 +169,7 @@ public:
|
||||
|
||||
|
||||
|
||||
|
||||
/** An inpoint - a combination of a transaction and an index n into its vin */
|
||||
class CInPoint
|
||||
{
|
||||
public:
|
||||
@@ -183,13 +178,13 @@ public:
|
||||
|
||||
CInPoint() { SetNull(); }
|
||||
CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; }
|
||||
void SetNull() { ptx = NULL; n = -1; }
|
||||
bool IsNull() const { return (ptx == NULL && n == -1); }
|
||||
void SetNull() { ptx = NULL; n = (unsigned int) -1; }
|
||||
bool IsNull() const { return (ptx == NULL && n == (unsigned int) -1); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/** An outpoint - a combination of a transaction hash and an index n into its vout */
|
||||
class COutPoint
|
||||
{
|
||||
public:
|
||||
@@ -199,8 +194,8 @@ public:
|
||||
COutPoint() { SetNull(); }
|
||||
COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; }
|
||||
IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
|
||||
void SetNull() { hash = 0; n = -1; }
|
||||
bool IsNull() const { return (hash == 0 && n == -1); }
|
||||
void SetNull() { hash = 0; n = (unsigned int) -1; }
|
||||
bool IsNull() const { return (hash == 0 && n == (unsigned int) -1); }
|
||||
|
||||
friend bool operator<(const COutPoint& a, const COutPoint& b)
|
||||
{
|
||||
@@ -219,7 +214,7 @@ public:
|
||||
|
||||
std::string ToString() const
|
||||
{
|
||||
return strprintf("COutPoint(%s, %d)", hash.ToString().substr(0,10).c_str(), n);
|
||||
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n);
|
||||
}
|
||||
|
||||
void print() const
|
||||
@@ -231,11 +226,10 @@ public:
|
||||
|
||||
|
||||
|
||||
//
|
||||
// An input of a transaction. It contains the location of the previous
|
||||
// transaction's output that it claims and a signature that matches the
|
||||
// output's public key.
|
||||
//
|
||||
/** An input of a transaction. It contains the location of the previous
|
||||
* transaction's output that it claims and a signature that matches the
|
||||
* output's public key.
|
||||
*/
|
||||
class CTxIn
|
||||
{
|
||||
public:
|
||||
@@ -289,7 +283,7 @@ public:
|
||||
std::string ToString() const
|
||||
{
|
||||
std::string str;
|
||||
str += strprintf("CTxIn(");
|
||||
str += "CTxIn(";
|
||||
str += prevout.ToString();
|
||||
if (prevout.IsNull())
|
||||
str += strprintf(", coinbase %s", HexStr(scriptSig).c_str());
|
||||
@@ -310,10 +304,9 @@ public:
|
||||
|
||||
|
||||
|
||||
//
|
||||
// An output of a transaction. It contains the public key that the next input
|
||||
// must be able to sign with to claim it.
|
||||
//
|
||||
/** An output of a transaction. It contains the public key that the next input
|
||||
* must be able to sign with to claim it.
|
||||
*/
|
||||
class CTxOut
|
||||
{
|
||||
public:
|
||||
@@ -389,13 +382,13 @@ enum GetMinFee_mode
|
||||
|
||||
typedef std::map<uint256, std::pair<CTxIndex, CTransaction> > MapPrevTx;
|
||||
|
||||
//
|
||||
// The basic transaction that is broadcasted on the network and contained in
|
||||
// blocks. A transaction can contain multiple inputs and outputs.
|
||||
//
|
||||
/** The basic transaction that is broadcasted on the network and contained in
|
||||
* blocks. A transaction can contain multiple inputs and outputs.
|
||||
*/
|
||||
class CTransaction
|
||||
{
|
||||
public:
|
||||
static const int CURRENT_VERSION=1;
|
||||
int nVersion;
|
||||
std::vector<CTxIn> vin;
|
||||
std::vector<CTxOut> vout;
|
||||
@@ -421,7 +414,7 @@ public:
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
nVersion = 1;
|
||||
nVersion = CTransaction::CURRENT_VERSION;
|
||||
vin.clear();
|
||||
vout.clear();
|
||||
nLockTime = 0;
|
||||
@@ -447,7 +440,7 @@ public:
|
||||
nBlockHeight = nBestHeight;
|
||||
if (nBlockTime == 0)
|
||||
nBlockTime = GetAdjustedTime();
|
||||
if ((int64)nLockTime < (nLockTime < LOCKTIME_THRESHOLD ? (int64)nBlockHeight : nBlockTime))
|
||||
if ((int64)nLockTime < ((int64)nLockTime < LOCKTIME_THRESHOLD ? (int64)nBlockHeight : nBlockTime))
|
||||
return true;
|
||||
BOOST_FOREACH(const CTxIn& txin, vin)
|
||||
if (!txin.IsFinal())
|
||||
@@ -459,13 +452,13 @@ public:
|
||||
{
|
||||
if (vin.size() != old.vin.size())
|
||||
return false;
|
||||
for (int i = 0; i < vin.size(); i++)
|
||||
for (unsigned int i = 0; i < vin.size(); i++)
|
||||
if (vin[i].prevout != old.vin[i].prevout)
|
||||
return false;
|
||||
|
||||
bool fNewer = false;
|
||||
unsigned int nLowest = std::numeric_limits<unsigned int>::max();
|
||||
for (int i = 0; i < vin.size(); i++)
|
||||
for (unsigned int i = 0; i < vin.size(); i++)
|
||||
{
|
||||
if (vin[i].nSequence != old.vin[i].nSequence)
|
||||
{
|
||||
@@ -505,7 +498,7 @@ public:
|
||||
@return number of sigops this transaction's outputs will produce when spent
|
||||
@see CTransaction::FetchInputs
|
||||
*/
|
||||
int GetLegacySigOpCount() const;
|
||||
unsigned int GetLegacySigOpCount() const;
|
||||
|
||||
/** Count ECDSA signature operations in pay-to-script-hash inputs.
|
||||
|
||||
@@ -513,7 +506,7 @@ public:
|
||||
@return maximum number of sigops required to validate this transaction's inputs
|
||||
@see CTransaction::FetchInputs
|
||||
*/
|
||||
int GetP2SHSigOpCount(const MapPrevTx& mapInputs) const;
|
||||
unsigned int GetP2SHSigOpCount(const MapPrevTx& mapInputs) const;
|
||||
|
||||
/** Amount of bitcoins spent by this transaction.
|
||||
@return sum of all outputs (note: does not include fees)
|
||||
@@ -547,62 +540,24 @@ public:
|
||||
return dPriority > COIN * 144 / 250;
|
||||
}
|
||||
|
||||
int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, enum GetMinFee_mode mode=GMF_BLOCK) const
|
||||
{
|
||||
// Base fee is either MIN_TX_FEE or MIN_RELAY_TX_FEE
|
||||
int64 nBaseFee = (mode == GMF_RELAY) ? MIN_RELAY_TX_FEE : MIN_TX_FEE;
|
||||
|
||||
unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK);
|
||||
unsigned int nNewBlockSize = nBlockSize + nBytes;
|
||||
int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee;
|
||||
|
||||
if (fAllowFree)
|
||||
{
|
||||
if (nBlockSize == 1)
|
||||
{
|
||||
// Transactions under 10K are free
|
||||
// (about 4500bc if made of 50bc inputs)
|
||||
if (nBytes < 10000)
|
||||
nMinFee = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Free transaction area
|
||||
if (nNewBlockSize < 27000)
|
||||
nMinFee = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// To limit dust spam, require MIN_TX_FEE/MIN_RELAY_TX_FEE if any output is less than 0.01
|
||||
if (nMinFee < nBaseFee)
|
||||
BOOST_FOREACH(const CTxOut& txout, vout)
|
||||
if (txout.nValue < CENT)
|
||||
nMinFee = nBaseFee;
|
||||
|
||||
// Raise the price as the block approaches full
|
||||
if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2)
|
||||
{
|
||||
if (nNewBlockSize >= MAX_BLOCK_SIZE_GEN)
|
||||
return MAX_MONEY;
|
||||
nMinFee *= MAX_BLOCK_SIZE_GEN / (MAX_BLOCK_SIZE_GEN - nNewBlockSize);
|
||||
}
|
||||
|
||||
if (!MoneyRange(nMinFee))
|
||||
nMinFee = MAX_MONEY;
|
||||
return nMinFee;
|
||||
}
|
||||
|
||||
int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, enum GetMinFee_mode mode=GMF_BLOCK) const;
|
||||
|
||||
bool ReadFromDisk(CDiskTxPos pos, FILE** pfileRet=NULL)
|
||||
{
|
||||
CAutoFile filein = OpenBlockFile(pos.nFile, 0, pfileRet ? "rb+" : "rb");
|
||||
CAutoFile filein = CAutoFile(OpenBlockFile(pos.nFile, 0, pfileRet ? "rb+" : "rb"), SER_DISK, CLIENT_VERSION);
|
||||
if (!filein)
|
||||
return error("CTransaction::ReadFromDisk() : OpenBlockFile failed");
|
||||
|
||||
// Read transaction
|
||||
if (fseek(filein, pos.nTxPos, SEEK_SET) != 0)
|
||||
return error("CTransaction::ReadFromDisk() : fseek failed");
|
||||
filein >> *this;
|
||||
|
||||
try {
|
||||
filein >> *this;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
// Return file pointer
|
||||
if (pfileRet)
|
||||
@@ -631,15 +586,15 @@ public:
|
||||
std::string ToString() const
|
||||
{
|
||||
std::string str;
|
||||
str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%d, vout.size=%d, nLockTime=%d)\n",
|
||||
str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%"PRIszu", vout.size=%"PRIszu", nLockTime=%u)\n",
|
||||
GetHash().ToString().substr(0,10).c_str(),
|
||||
nVersion,
|
||||
vin.size(),
|
||||
vout.size(),
|
||||
nLockTime);
|
||||
for (int i = 0; i < vin.size(); i++)
|
||||
for (unsigned int i = 0; i < vin.size(); i++)
|
||||
str += " " + vin[i].ToString() + "\n";
|
||||
for (int i = 0; i < vout.size(); i++)
|
||||
for (unsigned int i = 0; i < vout.size(); i++)
|
||||
str += " " + vout[i].ToString() + "\n";
|
||||
return str;
|
||||
}
|
||||
@@ -686,22 +641,16 @@ public:
|
||||
bool ClientConnectInputs();
|
||||
bool CheckTransaction() const;
|
||||
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);
|
||||
bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL);
|
||||
|
||||
protected:
|
||||
const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const;
|
||||
bool AddToMemoryPoolUnchecked();
|
||||
public:
|
||||
bool RemoveFromMemoryPool();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// A transaction with a merkle branch linking it to the block chain
|
||||
//
|
||||
/** A transaction with a merkle branch linking it to the block chain. */
|
||||
class CMerkleTx : public CTransaction
|
||||
{
|
||||
public:
|
||||
@@ -710,7 +659,7 @@ public:
|
||||
int nIndex;
|
||||
|
||||
// memory only
|
||||
mutable char fMerkleVerified;
|
||||
mutable bool fMerkleVerified;
|
||||
|
||||
|
||||
CMerkleTx()
|
||||
@@ -753,11 +702,10 @@ public:
|
||||
|
||||
|
||||
|
||||
//
|
||||
// A txdb record that contains the disk location of a transaction and the
|
||||
// locations of transactions that spend its outputs. vSpent is really only
|
||||
// used as a flag, but having the location is very helpful for debugging.
|
||||
//
|
||||
/** A txdb record that contains the disk location of a transaction and the
|
||||
* locations of transactions that spend its outputs. vSpent is really only
|
||||
* used as a flag, but having the location is very helpful for debugging.
|
||||
*/
|
||||
class CTxIndex
|
||||
{
|
||||
public:
|
||||
@@ -805,28 +753,28 @@ public:
|
||||
return !(a == b);
|
||||
}
|
||||
int GetDepthInMainChain() const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Nodes collect new transactions into a block, hash them into a hash tree,
|
||||
// and scan through nonce values to make the block's hash satisfy proof-of-work
|
||||
// requirements. When they solve the proof-of-work, they broadcast the block
|
||||
// to everyone and the block is added to the block chain. The first transaction
|
||||
// in the block is a special one that creates a new coin owned by the creator
|
||||
// of the block.
|
||||
//
|
||||
// Blocks are appended to blk0001.dat files on disk. Their location on disk
|
||||
// is indexed by CBlockIndex objects in memory.
|
||||
//
|
||||
/** Nodes collect new transactions into a block, hash them into a hash tree,
|
||||
* and scan through nonce values to make the block's hash satisfy proof-of-work
|
||||
* requirements. When they solve the proof-of-work, they broadcast the block
|
||||
* to everyone and the block is added to the block chain. The first transaction
|
||||
* in the block is a special one that creates a new coin owned by the creator
|
||||
* of the block.
|
||||
*
|
||||
* Blocks are appended to blk0001.dat files on disk. Their location on disk
|
||||
* is indexed by CBlockIndex objects in memory.
|
||||
*/
|
||||
class CBlock
|
||||
{
|
||||
public:
|
||||
// header
|
||||
static const int CURRENT_VERSION=2;
|
||||
int nVersion;
|
||||
uint256 hashPrevBlock;
|
||||
uint256 hashMerkleRoot;
|
||||
@@ -868,7 +816,7 @@ public:
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
nVersion = 1;
|
||||
nVersion = CBlock::CURRENT_VERSION;
|
||||
hashPrevBlock = 0;
|
||||
hashMerkleRoot = 0;
|
||||
nTime = 0;
|
||||
@@ -951,7 +899,7 @@ public:
|
||||
bool WriteToDisk(unsigned int& nFileRet, unsigned int& nBlockPosRet)
|
||||
{
|
||||
// Open history file to append
|
||||
CAutoFile fileout = AppendBlockFile(nFileRet);
|
||||
CAutoFile fileout = CAutoFile(AppendBlockFile(nFileRet), SER_DISK, CLIENT_VERSION);
|
||||
if (!fileout)
|
||||
return error("CBlock::WriteToDisk() : AppendBlockFile failed");
|
||||
|
||||
@@ -960,21 +908,16 @@ public:
|
||||
fileout << FLATDATA(pchMessageStart) << nSize;
|
||||
|
||||
// Write block
|
||||
nBlockPosRet = ftell(fileout);
|
||||
if (nBlockPosRet == -1)
|
||||
long fileOutPos = ftell(fileout);
|
||||
if (fileOutPos < 0)
|
||||
return error("CBlock::WriteToDisk() : ftell failed");
|
||||
nBlockPosRet = fileOutPos;
|
||||
fileout << *this;
|
||||
|
||||
// Flush stdio buffers and commit to disk before returning
|
||||
fflush(fileout);
|
||||
if (!IsInitialBlockDownload() || (nBestHeight+1) % 500 == 0)
|
||||
{
|
||||
#ifdef WIN32
|
||||
_commit(_fileno(fileout));
|
||||
#else
|
||||
fsync(fileno(fileout));
|
||||
#endif
|
||||
}
|
||||
FileCommit(fileout);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -984,14 +927,19 @@ public:
|
||||
SetNull();
|
||||
|
||||
// Open history file to read
|
||||
CAutoFile filein = OpenBlockFile(nFile, nBlockPos, "rb");
|
||||
CAutoFile filein = CAutoFile(OpenBlockFile(nFile, nBlockPos, "rb"), SER_DISK, CLIENT_VERSION);
|
||||
if (!filein)
|
||||
return error("CBlock::ReadFromDisk() : OpenBlockFile failed");
|
||||
if (!fReadTransactions)
|
||||
filein.nType |= SER_BLOCKHEADERONLY;
|
||||
|
||||
// Read block
|
||||
filein >> *this;
|
||||
try {
|
||||
filein >> *this;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
// Check the header
|
||||
if (!CheckProofOfWork(GetHash(), nBits))
|
||||
@@ -1004,31 +952,31 @@ public:
|
||||
|
||||
void print() const
|
||||
{
|
||||
printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%d)\n",
|
||||
printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
|
||||
GetHash().ToString().substr(0,20).c_str(),
|
||||
nVersion,
|
||||
hashPrevBlock.ToString().substr(0,20).c_str(),
|
||||
hashMerkleRoot.ToString().substr(0,10).c_str(),
|
||||
nTime, nBits, nNonce,
|
||||
vtx.size());
|
||||
for (int i = 0; i < vtx.size(); i++)
|
||||
for (unsigned int i = 0; i < vtx.size(); i++)
|
||||
{
|
||||
printf(" ");
|
||||
vtx[i].print();
|
||||
}
|
||||
printf(" vMerkleTree: ");
|
||||
for (int i = 0; i < vMerkleTree.size(); i++)
|
||||
for (unsigned int i = 0; i < vMerkleTree.size(); i++)
|
||||
printf("%s ", vMerkleTree[i].ToString().substr(0,10).c_str());
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
bool DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex);
|
||||
bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex);
|
||||
bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck=false);
|
||||
bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);
|
||||
bool SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew);
|
||||
bool AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos);
|
||||
bool CheckBlock() const;
|
||||
bool CheckBlock(bool fCheckPOW=true, bool fCheckMerkleRoot=true) const;
|
||||
bool AcceptBlock();
|
||||
|
||||
private:
|
||||
@@ -1040,14 +988,13 @@ private:
|
||||
|
||||
|
||||
|
||||
//
|
||||
// The block chain is a tree shaped structure starting with the
|
||||
// genesis block at the root, with each block potentially having multiple
|
||||
// candidates to be the next block. pprev and pnext link a path through the
|
||||
// main/longest chain. A blockindex may have multiple pprev pointing back
|
||||
// to it, but pnext will only point forward to the longest branch, or will
|
||||
// be null if the block is not part of the longest chain.
|
||||
//
|
||||
/** The block chain is a tree shaped structure starting with the
|
||||
* genesis block at the root, with each block potentially having multiple
|
||||
* candidates to be the next block. pprev and pnext link a path through the
|
||||
* main/longest chain. A blockindex may have multiple pprev pointing back
|
||||
* to it, but pnext will only point forward to the longest branch, or will
|
||||
* be null if the block is not part of the longest chain.
|
||||
*/
|
||||
class CBlockIndex
|
||||
{
|
||||
public:
|
||||
@@ -1143,21 +1090,6 @@ public:
|
||||
return CheckProofOfWork(GetBlockHash(), nBits);
|
||||
}
|
||||
|
||||
bool EraseBlockFromDisk()
|
||||
{
|
||||
// Open history file
|
||||
CAutoFile fileout = OpenBlockFile(nFile, nBlockPos, "rb+");
|
||||
if (!fileout)
|
||||
return false;
|
||||
|
||||
// Overwrite with empty null block
|
||||
CBlock block;
|
||||
block.SetNull();
|
||||
fileout << block;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
enum { nMedianTimeSpan=11 };
|
||||
|
||||
int64 GetMedianTimePast() const
|
||||
@@ -1186,11 +1118,17 @@ public:
|
||||
return pindex->GetMedianTimePast();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are nRequired or more blocks of minVersion or above
|
||||
* in the last nToCheck blocks, starting at pstart and going backwards.
|
||||
*/
|
||||
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart,
|
||||
unsigned int nRequired, unsigned int nToCheck);
|
||||
|
||||
|
||||
std::string ToString() const
|
||||
{
|
||||
return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nHeight=%d, merkle=%s, hashBlock=%s)",
|
||||
return strprintf("CBlockIndex(pprev=%p, pnext=%p, nFile=%u, nBlockPos=%-6u nHeight=%d, merkle=%s, hashBlock=%s)",
|
||||
pprev, pnext, nFile, nBlockPos, nHeight,
|
||||
hashMerkleRoot.ToString().substr(0,10).c_str(),
|
||||
GetBlockHash().ToString().substr(0,20).c_str());
|
||||
@@ -1204,9 +1142,7 @@ public:
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Used to marshal pointers into hashes for db storage.
|
||||
//
|
||||
/** Used to marshal pointers into hashes for db storage. */
|
||||
class CDiskBlockIndex : public CBlockIndex
|
||||
{
|
||||
public:
|
||||
@@ -1281,11 +1217,10 @@ public:
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Describes a place in the block chain to another node such that if the
|
||||
// other node doesn't have the same branch, it can find a recent common trunk.
|
||||
// The further back it is, the further before the fork it may be.
|
||||
//
|
||||
/** Describes a place in the block chain to another node such that if the
|
||||
* other node doesn't have the same branch, it can find a recent common trunk.
|
||||
* The further back it is, the further before the fork it may be.
|
||||
*/
|
||||
class CBlockLocator
|
||||
{
|
||||
protected:
|
||||
@@ -1416,205 +1351,37 @@ public:
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Alerts are for notifying old versions if they become too obsolete and
|
||||
// need to upgrade. The message is displayed in the status bar.
|
||||
// Alert messages are broadcast as a vector of signed data. Unserializing may
|
||||
// not read the entire buffer if the alert is for a newer version, but older
|
||||
// versions can still relay the original data.
|
||||
//
|
||||
class CUnsignedAlert
|
||||
class CTxMemPool
|
||||
{
|
||||
public:
|
||||
int nVersion;
|
||||
int64 nRelayUntil; // when newer nodes stop relaying to newer nodes
|
||||
int64 nExpiration;
|
||||
int nID;
|
||||
int nCancel;
|
||||
std::set<int> setCancel;
|
||||
int nMinVer; // lowest version inclusive
|
||||
int nMaxVer; // highest version inclusive
|
||||
std::set<std::string> setSubVer; // empty matches all
|
||||
int nPriority;
|
||||
mutable CCriticalSection cs;
|
||||
std::map<uint256, CTransaction> mapTx;
|
||||
std::map<COutPoint, CInPoint> mapNextTx;
|
||||
|
||||
// Actions
|
||||
std::string strComment;
|
||||
std::string strStatusBar;
|
||||
std::string strReserved;
|
||||
bool accept(CTxDB& txdb, CTransaction &tx,
|
||||
bool fCheckInputs, bool* pfMissingInputs);
|
||||
bool addUnchecked(const uint256& hash, CTransaction &tx);
|
||||
bool remove(CTransaction &tx);
|
||||
void clear();
|
||||
void queryHashes(std::vector<uint256>& vtxid);
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(
|
||||
READWRITE(this->nVersion);
|
||||
nVersion = this->nVersion;
|
||||
READWRITE(nRelayUntil);
|
||||
READWRITE(nExpiration);
|
||||
READWRITE(nID);
|
||||
READWRITE(nCancel);
|
||||
READWRITE(setCancel);
|
||||
READWRITE(nMinVer);
|
||||
READWRITE(nMaxVer);
|
||||
READWRITE(setSubVer);
|
||||
READWRITE(nPriority);
|
||||
|
||||
READWRITE(strComment);
|
||||
READWRITE(strStatusBar);
|
||||
READWRITE(strReserved);
|
||||
)
|
||||
|
||||
void SetNull()
|
||||
unsigned long size()
|
||||
{
|
||||
nVersion = 1;
|
||||
nRelayUntil = 0;
|
||||
nExpiration = 0;
|
||||
nID = 0;
|
||||
nCancel = 0;
|
||||
setCancel.clear();
|
||||
nMinVer = 0;
|
||||
nMaxVer = 0;
|
||||
setSubVer.clear();
|
||||
nPriority = 0;
|
||||
|
||||
strComment.clear();
|
||||
strStatusBar.clear();
|
||||
strReserved.clear();
|
||||
LOCK(cs);
|
||||
return mapTx.size();
|
||||
}
|
||||
|
||||
std::string ToString() const
|
||||
bool exists(uint256 hash)
|
||||
{
|
||||
std::string strSetCancel;
|
||||
BOOST_FOREACH(int n, setCancel)
|
||||
strSetCancel += strprintf("%d ", n);
|
||||
std::string strSetSubVer;
|
||||
BOOST_FOREACH(std::string str, setSubVer)
|
||||
strSetSubVer += "\"" + str + "\" ";
|
||||
return strprintf(
|
||||
"CAlert(\n"
|
||||
" nVersion = %d\n"
|
||||
" nRelayUntil = %"PRI64d"\n"
|
||||
" nExpiration = %"PRI64d"\n"
|
||||
" nID = %d\n"
|
||||
" nCancel = %d\n"
|
||||
" setCancel = %s\n"
|
||||
" nMinVer = %d\n"
|
||||
" nMaxVer = %d\n"
|
||||
" setSubVer = %s\n"
|
||||
" nPriority = %d\n"
|
||||
" strComment = \"%s\"\n"
|
||||
" strStatusBar = \"%s\"\n"
|
||||
")\n",
|
||||
nVersion,
|
||||
nRelayUntil,
|
||||
nExpiration,
|
||||
nID,
|
||||
nCancel,
|
||||
strSetCancel.c_str(),
|
||||
nMinVer,
|
||||
nMaxVer,
|
||||
strSetSubVer.c_str(),
|
||||
nPriority,
|
||||
strComment.c_str(),
|
||||
strStatusBar.c_str());
|
||||
return (mapTx.count(hash) != 0);
|
||||
}
|
||||
|
||||
void print() const
|
||||
CTransaction& lookup(uint256 hash)
|
||||
{
|
||||
printf("%s", ToString().c_str());
|
||||
return mapTx[hash];
|
||||
}
|
||||
};
|
||||
|
||||
class CAlert : public CUnsignedAlert
|
||||
{
|
||||
public:
|
||||
std::vector<unsigned char> vchMsg;
|
||||
std::vector<unsigned char> vchSig;
|
||||
|
||||
CAlert()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(
|
||||
READWRITE(vchMsg);
|
||||
READWRITE(vchSig);
|
||||
)
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
CUnsignedAlert::SetNull();
|
||||
vchMsg.clear();
|
||||
vchSig.clear();
|
||||
}
|
||||
|
||||
bool IsNull() const
|
||||
{
|
||||
return (nExpiration == 0);
|
||||
}
|
||||
|
||||
uint256 GetHash() const
|
||||
{
|
||||
return SerializeHash(*this);
|
||||
}
|
||||
|
||||
bool IsInEffect() const
|
||||
{
|
||||
return (GetAdjustedTime() < nExpiration);
|
||||
}
|
||||
|
||||
bool Cancels(const CAlert& alert) const
|
||||
{
|
||||
if (!IsInEffect())
|
||||
return false; // this was a no-op before 31403
|
||||
return (alert.nID <= nCancel || setCancel.count(alert.nID));
|
||||
}
|
||||
|
||||
bool AppliesTo(int nVersion, std::string strSubVerIn) const
|
||||
{
|
||||
// TODO: rework for client-version-embedded-in-strSubVer ?
|
||||
return (IsInEffect() &&
|
||||
nMinVer <= nVersion && nVersion <= nMaxVer &&
|
||||
(setSubVer.empty() || setSubVer.count(strSubVerIn)));
|
||||
}
|
||||
|
||||
bool AppliesToMe() const
|
||||
{
|
||||
return AppliesTo(PROTOCOL_VERSION, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<std::string>()));
|
||||
}
|
||||
|
||||
bool RelayTo(CNode* pnode) const
|
||||
{
|
||||
if (!IsInEffect())
|
||||
return false;
|
||||
// returns true if wasn't already contained in the set
|
||||
if (pnode->setKnown.insert(GetHash()).second)
|
||||
{
|
||||
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
|
||||
AppliesToMe() ||
|
||||
GetAdjustedTime() < nRelayUntil)
|
||||
{
|
||||
pnode->PushMessage("alert", *this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CheckSignature()
|
||||
{
|
||||
CKey key;
|
||||
if (!key.SetPubKey(ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284")))
|
||||
return error("CAlert::CheckSignature() : SetPubKey failed");
|
||||
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
|
||||
return error("CAlert::CheckSignature() : verify signature failed");
|
||||
|
||||
// Now unserialize the data
|
||||
CDataStream sMsg(vchMsg);
|
||||
sMsg >> *(CUnsignedAlert*)this;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessAlert();
|
||||
};
|
||||
extern CTxMemPool mempool;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,50 +1,66 @@
|
||||
# Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
# Distributed under the MIT/X11 software license, see the accompanying
|
||||
# file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
DEPSDIR:=/usr/i586-mingw32msvc
|
||||
|
||||
USE_UPNP:=0
|
||||
USE_IPV6:=1
|
||||
|
||||
INCLUDEPATHS= \
|
||||
-I"$(DEPSDIR)/boost_1_47_0" \
|
||||
-I"$(CURDIR)" \
|
||||
-I"$(CURDIR)"/obj \
|
||||
-I"$(DEPSDIR)/boost_1_50_0" \
|
||||
-I"$(DEPSDIR)/db-4.8.30.NC/build_unix" \
|
||||
-I"$(DEPSDIR)/openssl-1.0.0e/include" \
|
||||
-I"$(DEPSDIR)/openssl-1.0.1c/include" \
|
||||
-I"$(DEPSDIR)"
|
||||
|
||||
LIBPATHS= \
|
||||
-L"$(DEPSDIR)/boost_1_47_0/stage/lib" \
|
||||
-L"$(DEPSDIR)/boost_1_50_0/stage/lib" \
|
||||
-L"$(DEPSDIR)/db-4.8.30.NC/build_unix" \
|
||||
-L"$(DEPSDIR)/openssl-1.0.0e"
|
||||
-L"$(DEPSDIR)/openssl-1.0.1c"
|
||||
|
||||
LIBS= \
|
||||
-l boost_system-mt-s \
|
||||
-l boost_filesystem-mt-s \
|
||||
-l boost_program_options-mt-s \
|
||||
-l boost_thread_win32-mt-s \
|
||||
-l boost_chrono-mt-s \
|
||||
-l db_cxx \
|
||||
-l ssl \
|
||||
-l crypto
|
||||
|
||||
DEFS=-D_MT -DWIN32 -D_WINDOWS -DNOPCH -DUSE_SSL -DBOOST_THREAD_USE_LIB
|
||||
DEFS=-D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE
|
||||
DEBUGFLAGS=-g
|
||||
CFLAGS=-O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
||||
CFLAGS=-O2 -w -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
||||
LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat
|
||||
|
||||
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||
|
||||
ifdef USE_UPNP
|
||||
ifndef USE_UPNP
|
||||
override USE_UPNP = -
|
||||
endif
|
||||
ifneq (${USE_UPNP}, -)
|
||||
LIBPATHS += -L"$(DEPSDIR)/miniupnpc"
|
||||
LIBS += -l miniupnpc -l iphlpapi
|
||||
DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP)
|
||||
endif
|
||||
|
||||
LIBS += -l mingwthrd -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l shlwapi
|
||||
ifneq (${USE_IPV6}, -)
|
||||
DEFS += -DUSE_IPV6=$(USE_IPV6)
|
||||
endif
|
||||
|
||||
LIBS += -l mingwthrd -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l mswsock -l shlwapi
|
||||
|
||||
# TODO: make the mingw builds smarter about dependencies, like the linux/osx builds are
|
||||
HEADERS = $(wildcard *.h)
|
||||
|
||||
OBJS= \
|
||||
obj/alert.o \
|
||||
obj/version.o \
|
||||
obj/checkpoints.o \
|
||||
obj/netbase.o \
|
||||
obj/addrman.o \
|
||||
obj/crypter.o \
|
||||
obj/key.o \
|
||||
obj/db.o \
|
||||
@@ -56,30 +72,45 @@ OBJS= \
|
||||
obj/protocol.o \
|
||||
obj/bitcoinrpc.o \
|
||||
obj/rpcdump.o \
|
||||
obj/rpcnet.o \
|
||||
obj/rpcmining.o \
|
||||
obj/rpcwallet.o \
|
||||
obj/rpcblockchain.o \
|
||||
obj/rpcrawtransaction.o \
|
||||
obj/script.o \
|
||||
obj/sync.o \
|
||||
obj/util.o \
|
||||
obj/wallet.o
|
||||
obj/wallet.o \
|
||||
obj/walletdb.o \
|
||||
obj/noui.o
|
||||
|
||||
all: bitcoind.exe
|
||||
|
||||
obj/build.h: FORCE
|
||||
/bin/sh ../share/genbuild.sh obj/build.h
|
||||
version.cpp: obj/build.h
|
||||
DEFS += -DHAVE_BUILD_INFO
|
||||
|
||||
obj/%.o: %.cpp $(HEADERS)
|
||||
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
|
||||
|
||||
bitcoind.exe: $(OBJS:obj/%=obj/%)
|
||||
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||
i586-mingw32msvc-g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||
|
||||
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
||||
|
||||
obj/test/%.o: obj/test/%.cpp $(HEADERS)
|
||||
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
|
||||
obj-test/%.o: test/%.cpp $(HEADERS)
|
||||
i586-mingw32msvc-g++ -c $(TESTDEFS) $(CFLAGS) -o $@ $<
|
||||
|
||||
test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
||||
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework-mt-s
|
||||
test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
||||
i586-mingw32msvc-g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework-mt-s $(LIBS)
|
||||
|
||||
|
||||
clean:
|
||||
-rm -f obj/*.o
|
||||
-rm -f obj/test/*.o
|
||||
-rm -f test/*.o
|
||||
-rm -f headers.h.gch
|
||||
-rm -f bitcoind.exe
|
||||
-rm -f obj-test/*.o
|
||||
-rm -f test_bitcoin.exe
|
||||
-rm -f obj/build.h
|
||||
|
||||
FORCE:
|
||||
|
||||
@@ -1,48 +1,62 @@
|
||||
# Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
# Distributed under the MIT/X11 software license, see the accompanying
|
||||
# file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
USE_UPNP:=0
|
||||
USE_IPV6:=1
|
||||
|
||||
INCLUDEPATHS= \
|
||||
-I"C:\boost-1.47.0-mgw" \
|
||||
-I"C:\boost-1.50.0-mgw" \
|
||||
-I"C:\db-4.8.30.NC-mgw\build_unix" \
|
||||
-I"C:\openssl-1.0.0d-mgw\include"
|
||||
-I"C:\openssl-1.0.1c-mgw\include"
|
||||
|
||||
LIBPATHS= \
|
||||
-L"C:\boost-1.47.0-mgw\stage\lib" \
|
||||
-L"C:\boost-1.50.0-mgw\stage\lib" \
|
||||
-L"C:\db-4.8.30.NC-mgw\build_unix" \
|
||||
-L"C:\openssl-1.0.0d-mgw"
|
||||
-L"C:\openssl-1.0.1c-mgw"
|
||||
|
||||
LIBS= \
|
||||
-l boost_system-mgw45-mt-s-1_47 \
|
||||
-l boost_filesystem-mgw45-mt-s-1_47 \
|
||||
-l boost_program_options-mgw45-mt-s-1_47 \
|
||||
-l boost_thread-mgw45-mt-s-1_47 \
|
||||
-l boost_system-mgw45-mt-s-1_50 \
|
||||
-l boost_filesystem-mgw45-mt-s-1_50 \
|
||||
-l boost_program_options-mgw45-mt-s-1_50 \
|
||||
-l boost_thread-mgw45-mt-s-1_50 \
|
||||
-l boost_chrono-mgw45-mt-s-1_50 \
|
||||
-l db_cxx \
|
||||
-l ssl \
|
||||
-l crypto
|
||||
|
||||
DEFS=-DWIN32 -D_WINDOWS -DNOPCH -DUSE_SSL -DBOOST_THREAD_USE_LIB
|
||||
DEFS=-DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE
|
||||
DEBUGFLAGS=-g
|
||||
CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
||||
CFLAGS=-mthreads -O2 -w -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
||||
LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat
|
||||
|
||||
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||
|
||||
ifdef USE_UPNP
|
||||
ifndef USE_UPNP
|
||||
override USE_UPNP = -
|
||||
endif
|
||||
ifneq (${USE_UPNP}, -)
|
||||
INCLUDEPATHS += -I"C:\miniupnpc-1.6-mgw"
|
||||
LIBPATHS += -L"C:\miniupnpc-1.6-mgw"
|
||||
LIBS += -l miniupnpc -l iphlpapi
|
||||
DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP)
|
||||
endif
|
||||
|
||||
LIBS += -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l shlwapi
|
||||
ifneq (${USE_IPV6}, -)
|
||||
DEFS += -DUSE_IPV6=$(USE_IPV6)
|
||||
endif
|
||||
|
||||
LIBS += -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l mswsock -l shlwapi
|
||||
|
||||
# TODO: make the mingw builds smarter about dependencies, like the linux/osx builds are
|
||||
HEADERS = $(wildcard *.h)
|
||||
|
||||
OBJS= \
|
||||
obj/alert.o \
|
||||
obj/version.o \
|
||||
obj/checkpoints.o \
|
||||
obj/netbase.o \
|
||||
obj/addrman.o \
|
||||
obj/crypter.o \
|
||||
obj/key.o \
|
||||
obj/db.o \
|
||||
@@ -54,29 +68,41 @@ OBJS= \
|
||||
obj/protocol.o \
|
||||
obj/bitcoinrpc.o \
|
||||
obj/rpcdump.o \
|
||||
obj/rpcnet.o \
|
||||
obj/rpcmining.o \
|
||||
obj/rpcwallet.o \
|
||||
obj/rpcblockchain.o \
|
||||
obj/rpcrawtransaction.o \
|
||||
obj/script.o \
|
||||
obj/sync.o \
|
||||
obj/util.o \
|
||||
obj/wallet.o
|
||||
obj/wallet.o \
|
||||
obj/walletdb.o \
|
||||
obj/noui.o
|
||||
|
||||
|
||||
all: bitcoind.exe
|
||||
|
||||
test check: test_bitcoin.exe FORCE
|
||||
test_bitcoin.exe
|
||||
|
||||
obj/%.o: %.cpp $(HEADERS)
|
||||
g++ -c $(CFLAGS) -o $@ $<
|
||||
|
||||
bitcoind.exe: $(OBJS:obj/%=obj/%)
|
||||
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||
g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||
|
||||
obj/test/test_bitcoin.o: $(wildcard test/*.cpp) $(HEADERS)
|
||||
g++ -c $(CFLAGS) -o $@ test/test_bitcoin.cpp
|
||||
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
||||
|
||||
test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
||||
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||
obj-test/%.o: test/%.cpp $(HEADERS)
|
||||
g++ -c $(TESTDEFS) $(CFLAGS) -o $@ $<
|
||||
|
||||
test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
||||
g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework $(LIBS)
|
||||
|
||||
clean:
|
||||
-del /Q bitcoind test_bitcoin
|
||||
-del /Q obj\*
|
||||
-del /Q obj\nogui\*
|
||||
-del /Q obj\test\*
|
||||
-del /Q test\*.o
|
||||
-del /Q headers.h.gch
|
||||
-del /Q obj-test\*
|
||||
|
||||
FORCE:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- mode: Makefile; -*-
|
||||
# Copyright (c) 2011 Bitcoin Developers
|
||||
# Distributed under the MIT/X11 software license, see the accompanying
|
||||
# file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
# Mac OS X makefile for bitcoin
|
||||
# Originally by Laszlo Hanyecz (solar@heliacal.net)
|
||||
@@ -11,6 +11,7 @@ DEPSDIR=/opt/local
|
||||
|
||||
INCLUDEPATHS= \
|
||||
-I"$(CURDIR)" \
|
||||
-I"$(CURDIR)"/obj \
|
||||
-I"$(DEPSDIR)/include" \
|
||||
-I"$(DEPSDIR)/include/db48"
|
||||
|
||||
@@ -19,8 +20,12 @@ LIBPATHS= \
|
||||
-L"$(DEPSDIR)/lib/db48"
|
||||
|
||||
USE_UPNP:=1
|
||||
USE_IPV6:=1
|
||||
|
||||
LIBS= -dead_strip
|
||||
|
||||
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||
|
||||
ifdef STATIC
|
||||
# Build STATIC if you are redistributing the bitcoind binary
|
||||
TESTLIBS += \
|
||||
@@ -49,17 +54,27 @@ LIBS += \
|
||||
TESTDEFS += -DBOOST_TEST_DYN_LINK
|
||||
endif
|
||||
|
||||
DEFS=-DMAC_OSX -DMSG_NOSIGNAL=0 -DUSE_SSL
|
||||
DEFS=-DMAC_OSX -DMSG_NOSIGNAL=0 -DBOOST_SPIRIT_THREADSAFE
|
||||
|
||||
ifdef RELEASE
|
||||
# Compile for maximum compatibility and smallest size.
|
||||
# This requires that dependencies are compiled
|
||||
# the same way.
|
||||
CFLAGS = -mmacosx-version-min=10.5 -arch i386 -O3
|
||||
else
|
||||
CFLAGS = -g
|
||||
endif
|
||||
|
||||
DEBUGFLAGS=-g
|
||||
# ppc doesn't work because we don't support big-endian
|
||||
CFLAGS=-mmacosx-version-min=10.5 -arch i386 -O3 \
|
||||
-Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat-security \
|
||||
CFLAGS += -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
|
||||
$(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
||||
|
||||
OBJS= \
|
||||
obj/alert.o \
|
||||
obj/version.o \
|
||||
obj/checkpoints.o \
|
||||
obj/netbase.o \
|
||||
obj/addrman.o \
|
||||
obj/crypter.o \
|
||||
obj/key.o \
|
||||
obj/db.o \
|
||||
@@ -71,11 +86,22 @@ OBJS= \
|
||||
obj/protocol.o \
|
||||
obj/bitcoinrpc.o \
|
||||
obj/rpcdump.o \
|
||||
obj/rpcnet.o \
|
||||
obj/rpcmining.o \
|
||||
obj/rpcwallet.o \
|
||||
obj/rpcblockchain.o \
|
||||
obj/rpcrawtransaction.o \
|
||||
obj/script.o \
|
||||
obj/sync.o \
|
||||
obj/util.o \
|
||||
obj/wallet.o
|
||||
obj/wallet.o \
|
||||
obj/walletdb.o \
|
||||
obj/noui.o
|
||||
|
||||
ifdef USE_UPNP
|
||||
ifndef USE_UPNP
|
||||
override USE_UPNP = -
|
||||
endif
|
||||
ifneq (${USE_UPNP}, -)
|
||||
DEFS += -DUSE_UPNP=$(USE_UPNP)
|
||||
ifdef STATIC
|
||||
LIBS += $(DEPSDIR)/lib/libminiupnpc.a
|
||||
@@ -84,14 +110,26 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq (${USE_IPV6}, -)
|
||||
DEFS += -DUSE_IPV6=$(USE_IPV6)
|
||||
endif
|
||||
|
||||
all: bitcoind
|
||||
|
||||
test check: test_bitcoin FORCE
|
||||
./test_bitcoin
|
||||
|
||||
# auto-generated dependencies:
|
||||
-include obj/*.P
|
||||
-include obj-test/*.P
|
||||
|
||||
obj/build.h: FORCE
|
||||
/bin/sh ../share/genbuild.sh obj/build.h
|
||||
version.cpp: obj/build.h
|
||||
DEFS += -DHAVE_BUILD_INFO
|
||||
|
||||
obj/%.o: %.cpp
|
||||
$(CXX) -c $(CFLAGS) -MMD -o $@ $<
|
||||
$(CXX) -c $(CFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
||||
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
||||
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
||||
@@ -103,7 +141,7 @@ bitcoind: $(OBJS:obj/%=obj/%)
|
||||
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
||||
|
||||
obj-test/%.o: test/%.cpp
|
||||
$(CXX) -c $(TESTDEFS) $(CFLAGS) -MMD -o $@ $<
|
||||
$(CXX) -c $(TESTDEFS) $(CFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
||||
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
||||
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
||||
@@ -118,3 +156,6 @@ clean:
|
||||
-rm -f obj-test/*.o
|
||||
-rm -f obj/*.P
|
||||
-rm -f obj-test/*.P
|
||||
-rm -f obj/build.h
|
||||
|
||||
FORCE:
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
# Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
# Distributed under the MIT/X11 software license, see the accompanying
|
||||
# file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
USE_UPNP:=0
|
||||
USE_IPV6:=1
|
||||
|
||||
DEFS=-DNOPCH
|
||||
LINK:=$(CXX)
|
||||
|
||||
DEFS += $(addprefix -I,$(CURDIR) $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
|
||||
DEFS=-DBOOST_SPIRIT_THREADSAFE
|
||||
|
||||
DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
|
||||
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
|
||||
|
||||
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||
|
||||
LMODE = dynamic
|
||||
LMODE2 = dynamic
|
||||
ifdef STATIC
|
||||
@@ -39,8 +44,8 @@ ifneq (${USE_UPNP}, -)
|
||||
DEFS += -DUSE_UPNP=$(USE_UPNP)
|
||||
endif
|
||||
|
||||
ifneq (${USE_SSL}, 0)
|
||||
DEFS += -DUSE_SSL
|
||||
ifneq (${USE_IPV6}, -)
|
||||
DEFS += -DUSE_IPV6=$(USE_IPV6)
|
||||
endif
|
||||
|
||||
LIBS+= \
|
||||
@@ -68,13 +73,14 @@ LIBS+= \
|
||||
# Make some important things such as the global offset table read only as soon as
|
||||
# the dynamic linker is finished building it. This will prevent overwriting of addresses
|
||||
# which would later be jumped to.
|
||||
HARDENING+=-Wl,-z,relro -Wl,-z,now
|
||||
LDHARDENING+=-Wl,-z,relro -Wl,-z,now
|
||||
|
||||
# Build position independent code to take advantage of Address Space Layout Randomization
|
||||
# offered by some kernels.
|
||||
# see doc/build-unix.txt for more information.
|
||||
ifdef PIE
|
||||
HARDENING+=-fPIE -pie
|
||||
HARDENING+=-fPIE
|
||||
LDHARDENING+=-pie
|
||||
endif
|
||||
|
||||
# -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
|
||||
@@ -84,13 +90,22 @@ LIBS+= \
|
||||
|
||||
|
||||
DEBUGFLAGS=-g
|
||||
CXXFLAGS=-O2
|
||||
xCXXFLAGS=-pthread -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat-security \
|
||||
|
||||
# CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
|
||||
# adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
|
||||
xCXXFLAGS=-O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
|
||||
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
|
||||
|
||||
# LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
|
||||
# adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
|
||||
xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
|
||||
|
||||
OBJS= \
|
||||
obj/alert.o \
|
||||
obj/version.o \
|
||||
obj/checkpoints.o \
|
||||
obj/netbase.o \
|
||||
obj/addrman.o \
|
||||
obj/crypter.o \
|
||||
obj/key.o \
|
||||
obj/db.o \
|
||||
@@ -102,38 +117,54 @@ OBJS= \
|
||||
obj/protocol.o \
|
||||
obj/bitcoinrpc.o \
|
||||
obj/rpcdump.o \
|
||||
obj/rpcnet.o \
|
||||
obj/rpcmining.o \
|
||||
obj/rpcwallet.o \
|
||||
obj/rpcblockchain.o \
|
||||
obj/rpcrawtransaction.o \
|
||||
obj/script.o \
|
||||
obj/sync.o \
|
||||
obj/util.o \
|
||||
obj/wallet.o
|
||||
obj/wallet.o \
|
||||
obj/walletdb.o \
|
||||
obj/noui.o
|
||||
|
||||
|
||||
all: bitcoind
|
||||
|
||||
test check: test_bitcoin FORCE
|
||||
./test_bitcoin
|
||||
|
||||
# auto-generated dependencies:
|
||||
-include obj/*.P
|
||||
-include obj-test/*.P
|
||||
|
||||
obj/build.h: FORCE
|
||||
/bin/sh ../share/genbuild.sh obj/build.h
|
||||
version.cpp: obj/build.h
|
||||
DEFS += -DHAVE_BUILD_INFO
|
||||
|
||||
obj/%.o: %.cpp
|
||||
$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
|
||||
$(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
||||
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
||||
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
||||
rm -f $(@:%.o=%.d)
|
||||
|
||||
bitcoind: $(OBJS:obj/%=obj/%)
|
||||
$(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
|
||||
$(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
|
||||
|
||||
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
||||
|
||||
obj-test/%.o: test/%.cpp
|
||||
$(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
|
||||
$(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
||||
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
||||
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
||||
rm -f $(@:%.o=%.d)
|
||||
|
||||
test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
||||
$(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
|
||||
$(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)
|
||||
|
||||
clean:
|
||||
-rm -f bitcoind test_bitcoin
|
||||
@@ -141,3 +172,6 @@ clean:
|
||||
-rm -f obj-test/*.o
|
||||
-rm -f obj/*.P
|
||||
-rm -f obj-test/*.P
|
||||
-rm -f obj/build.h
|
||||
|
||||
FORCE:
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// Copyright (c) 2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_MRUSET_H
|
||||
#define BITCOIN_MRUSET_H
|
||||
|
||||
#include <set>
|
||||
#include <deque>
|
||||
|
||||
/** STL-like set container that only keeps the most recent N elements. */
|
||||
template <typename T> class mruset
|
||||
{
|
||||
public:
|
||||
@@ -50,7 +51,7 @@ public:
|
||||
size_type max_size(size_type s)
|
||||
{
|
||||
if (s)
|
||||
while (queue.size() >= s)
|
||||
while (queue.size() > s)
|
||||
{
|
||||
set.erase(queue.front());
|
||||
queue.pop_front();
|
||||
|
||||
1190
src/net.cpp
1190
src/net.cpp
File diff suppressed because it is too large
Load Diff
201
src/net.h
201
src/net.h
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_NET_H
|
||||
#define BITCOIN_NET_H
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#include "mruset.h"
|
||||
#include "netbase.h"
|
||||
#include "protocol.h"
|
||||
#include "addrman.h"
|
||||
|
||||
class CAddrDB;
|
||||
class CRequestTracker;
|
||||
class CNode;
|
||||
class CBlockIndex;
|
||||
@@ -26,24 +26,48 @@ extern int nBestHeight;
|
||||
|
||||
|
||||
|
||||
inline unsigned int ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 10*1000); }
|
||||
inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 10*1000); }
|
||||
static const unsigned int PUBLISH_HOPS = 5;
|
||||
inline unsigned int ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
|
||||
inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
|
||||
|
||||
void AddOneShot(std::string strDest);
|
||||
bool RecvLine(SOCKET hSocket, std::string& strLine);
|
||||
bool GetMyExternalIP(CNetAddr& ipRet);
|
||||
bool AddAddress(CAddress addr, int64 nTimePenalty=0, CAddrDB *pAddrDB=NULL);
|
||||
void AddressCurrentlyConnected(const CService& addr);
|
||||
CNode* FindNode(const CNetAddr& ip);
|
||||
CNode* FindNode(const CService& ip);
|
||||
CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0);
|
||||
void AbandonRequests(void (*fn)(void*, CDataStream&), void* param1);
|
||||
bool AnySubscribed(unsigned int nChannel);
|
||||
void MapPort(bool fMapPort);
|
||||
bool BindListenPort(std::string& strError=REF(std::string()));
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL, int64 nTimeout=0);
|
||||
void MapPort();
|
||||
unsigned short GetListenPort();
|
||||
bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
|
||||
void StartNode(void* parg);
|
||||
bool StopNode();
|
||||
|
||||
enum
|
||||
{
|
||||
LOCAL_NONE, // unknown
|
||||
LOCAL_IF, // address a local interface listens on
|
||||
LOCAL_BIND, // address explicit bound to
|
||||
LOCAL_UPNP, // address reported by UPnP
|
||||
LOCAL_IRC, // address reported by IRC (deprecated)
|
||||
LOCAL_HTTP, // address reported by whatismyip.com and similar
|
||||
LOCAL_MANUAL, // address explicitly specified (-externalip=)
|
||||
|
||||
LOCAL_MAX
|
||||
};
|
||||
|
||||
void SetLimited(enum Network net, bool fLimited = true);
|
||||
bool IsLimited(enum Network net);
|
||||
bool IsLimited(const CNetAddr& addr);
|
||||
bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
|
||||
bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
|
||||
bool SeenLocal(const CService& addr);
|
||||
bool IsLocal(const CService& addr);
|
||||
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
|
||||
bool IsReachable(const CNetAddr &addr);
|
||||
void SetReachable(enum Network net, bool fFlag = true);
|
||||
CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL);
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
MSG_TX = 1,
|
||||
@@ -69,32 +93,33 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Thread types */
|
||||
enum threadId
|
||||
{
|
||||
THREAD_SOCKETHANDLER,
|
||||
THREAD_OPENCONNECTIONS,
|
||||
THREAD_MESSAGEHANDLER,
|
||||
THREAD_MINER,
|
||||
THREAD_RPCSERVER,
|
||||
THREAD_RPCLISTENER,
|
||||
THREAD_UPNP,
|
||||
THREAD_DNSSEED,
|
||||
THREAD_ADDEDCONNECTIONS,
|
||||
THREAD_DUMPADDRESS,
|
||||
THREAD_RPCHANDLER,
|
||||
|
||||
THREAD_MAX
|
||||
};
|
||||
|
||||
extern bool fClient;
|
||||
extern bool fAllowDNS;
|
||||
extern bool fDiscover;
|
||||
extern bool fUseUPnP;
|
||||
extern uint64 nLocalServices;
|
||||
extern CAddress addrLocalHost;
|
||||
extern uint64 nLocalHostNonce;
|
||||
extern boost::array<int, THREAD_MAX> vnThreadsRunning;
|
||||
extern CAddrMan addrman;
|
||||
|
||||
extern std::vector<CNode*> vNodes;
|
||||
extern CCriticalSection cs_vNodes;
|
||||
extern std::map<std::vector<unsigned char>, CAddress> mapAddresses;
|
||||
extern CCriticalSection cs_mapAddresses;
|
||||
extern std::map<CInv, CDataStream> mapRelay;
|
||||
extern std::deque<std::pair<int64, CInv> > vRelayExpiration;
|
||||
extern CCriticalSection cs_mapRelay;
|
||||
@@ -103,9 +128,27 @@ extern std::map<CInv, int64> mapAlreadyAskedFor;
|
||||
|
||||
|
||||
|
||||
class CNodeStats
|
||||
{
|
||||
public:
|
||||
uint64 nServices;
|
||||
int64 nLastSend;
|
||||
int64 nLastRecv;
|
||||
int64 nTimeConnected;
|
||||
std::string addrName;
|
||||
int nVersion;
|
||||
std::string strSubVer;
|
||||
bool fInbound;
|
||||
int64 nReleaseTime;
|
||||
int nStartingHeight;
|
||||
int nMisbehavior;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Information about a peer */
|
||||
class CNode
|
||||
{
|
||||
public:
|
||||
@@ -120,21 +163,25 @@ public:
|
||||
int64 nLastRecv;
|
||||
int64 nLastSendEmpty;
|
||||
int64 nTimeConnected;
|
||||
unsigned int nHeaderStart;
|
||||
int nHeaderStart;
|
||||
unsigned int nMessageStart;
|
||||
CAddress addr;
|
||||
std::string addrName;
|
||||
CService addrLocal;
|
||||
int nVersion;
|
||||
std::string strSubVer;
|
||||
bool fOneShot;
|
||||
bool fClient;
|
||||
bool fInbound;
|
||||
bool fNetworkNode;
|
||||
bool fSuccessfullyConnected;
|
||||
bool fDisconnect;
|
||||
CSemaphoreGrant grantOutbound;
|
||||
protected:
|
||||
int nRefCount;
|
||||
|
||||
// Denial-of-service detection/prevention
|
||||
// Key is ip address, value is banned-until-time
|
||||
// Key is IP address, value is banned-until-time
|
||||
static std::map<CNetAddr, int64> setBanned;
|
||||
static CCriticalSection cs_setBanned;
|
||||
int nMisbehavior;
|
||||
@@ -160,17 +207,10 @@ public:
|
||||
CCriticalSection cs_inventory;
|
||||
std::multimap<int64, CInv> mapAskFor;
|
||||
|
||||
// publish and subscription
|
||||
std::vector<char> vfSubscribe;
|
||||
|
||||
CNode(SOCKET hSocketIn, CAddress addrIn, bool fInboundIn=false)
|
||||
CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : vSend(SER_NETWORK, MIN_PROTO_VERSION), vRecv(SER_NETWORK, MIN_PROTO_VERSION)
|
||||
{
|
||||
nServices = 0;
|
||||
hSocket = hSocketIn;
|
||||
vSend.SetType(SER_NETWORK);
|
||||
vRecv.SetType(SER_NETWORK);
|
||||
vSend.SetVersion(209);
|
||||
vRecv.SetVersion(209);
|
||||
nLastSend = 0;
|
||||
nLastRecv = 0;
|
||||
nLastSendEmpty = GetTime();
|
||||
@@ -178,8 +218,10 @@ public:
|
||||
nHeaderStart = -1;
|
||||
nMessageStart = -1;
|
||||
addr = addrIn;
|
||||
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
|
||||
nVersion = 0;
|
||||
strSubVer = "";
|
||||
fOneShot = false;
|
||||
fClient = false; // set by version message
|
||||
fInbound = fInboundIn;
|
||||
fNetworkNode = false;
|
||||
@@ -192,7 +234,6 @@ public:
|
||||
hashLastGetBlocksEnd = 0;
|
||||
nStartingHeight = -1;
|
||||
fGetAddr = false;
|
||||
vfSubscribe.assign(256, false);
|
||||
nMisbehavior = 0;
|
||||
setInventoryKnown.max_size(SendBufferSize() / 1000);
|
||||
|
||||
@@ -254,15 +295,19 @@ public:
|
||||
|
||||
void AddInventoryKnown(const CInv& inv)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_inventory)
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
setInventoryKnown.insert(inv);
|
||||
}
|
||||
}
|
||||
|
||||
void PushInventory(const CInv& inv)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_inventory)
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
if (!setInventoryKnown.count(inv))
|
||||
vInventoryToSend.push_back(inv);
|
||||
}
|
||||
}
|
||||
|
||||
void AskFor(const CInv& inv)
|
||||
@@ -270,7 +315,8 @@ public:
|
||||
// We're using mapAskFor as a priority queue,
|
||||
// the key is the earliest time the request can be sent
|
||||
int64& nRequestTime = mapAlreadyAskedFor[inv];
|
||||
printf("askfor %s %"PRI64d"\n", inv.ToString().c_str(), nRequestTime);
|
||||
if (fDebugNet)
|
||||
printf("askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
|
||||
|
||||
// Make sure not to reuse time indexes to keep things in the same order
|
||||
int64 nNow = (GetTime() - 1) * 1000000;
|
||||
@@ -294,15 +340,13 @@ public:
|
||||
nHeaderStart = vSend.size();
|
||||
vSend << CMessageHeader(pszCommand, 0);
|
||||
nMessageStart = vSend.size();
|
||||
if (fDebug) {
|
||||
printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
|
||||
if (fDebug)
|
||||
printf("sending: %s ", pszCommand);
|
||||
}
|
||||
}
|
||||
|
||||
void AbortMessage()
|
||||
{
|
||||
if (nHeaderStart == -1)
|
||||
if (nHeaderStart < 0)
|
||||
return;
|
||||
vSend.resize(nHeaderStart);
|
||||
nHeaderStart = -1;
|
||||
@@ -322,19 +366,19 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
if (nHeaderStart == -1)
|
||||
if (nHeaderStart < 0)
|
||||
return;
|
||||
|
||||
// Set the size
|
||||
unsigned int nSize = vSend.size() - nMessageStart;
|
||||
memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize));
|
||||
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize));
|
||||
|
||||
// Set the checksum
|
||||
uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());
|
||||
unsigned int nChecksum = 0;
|
||||
memcpy(&nChecksum, &hash, sizeof(nChecksum));
|
||||
assert(nMessageStart - nHeaderStart >= offsetof(CMessageHeader, nChecksum) + sizeof(nChecksum));
|
||||
memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nChecksum), &nChecksum, sizeof(nChecksum));
|
||||
assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
|
||||
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum));
|
||||
|
||||
if (fDebug) {
|
||||
printf("(%d bytes)\n", nSize);
|
||||
@@ -347,7 +391,7 @@ public:
|
||||
|
||||
void EndMessageAbortIfEmpty()
|
||||
{
|
||||
if (nHeaderStart == -1)
|
||||
if (nHeaderStart < 0)
|
||||
return;
|
||||
int nSize = vSend.size() - nMessageStart;
|
||||
if (nSize > 0)
|
||||
@@ -526,8 +570,10 @@ public:
|
||||
uint256 hashReply;
|
||||
RAND_bytes((unsigned char*)&hashReply, sizeof(hashReply));
|
||||
|
||||
CRITICAL_BLOCK(cs_mapRequests)
|
||||
{
|
||||
LOCK(cs_mapRequests);
|
||||
mapRequests[hashReply] = CRequestTracker(fn, param1);
|
||||
}
|
||||
|
||||
PushMessage(pszCommand, hashReply);
|
||||
}
|
||||
@@ -539,8 +585,10 @@ public:
|
||||
uint256 hashReply;
|
||||
RAND_bytes((unsigned char*)&hashReply, sizeof(hashReply));
|
||||
|
||||
CRITICAL_BLOCK(cs_mapRequests)
|
||||
{
|
||||
LOCK(cs_mapRequests);
|
||||
mapRequests[hashReply] = CRequestTracker(fn, param1);
|
||||
}
|
||||
|
||||
PushMessage(pszCommand, hashReply, a1);
|
||||
}
|
||||
@@ -552,8 +600,10 @@ public:
|
||||
uint256 hashReply;
|
||||
RAND_bytes((unsigned char*)&hashReply, sizeof(hashReply));
|
||||
|
||||
CRITICAL_BLOCK(cs_mapRequests)
|
||||
{
|
||||
LOCK(cs_mapRequests);
|
||||
mapRequests[hashReply] = CRequestTracker(fn, param1);
|
||||
}
|
||||
|
||||
PushMessage(pszCommand, hashReply, a1, a2);
|
||||
}
|
||||
@@ -585,6 +635,7 @@ public:
|
||||
static void ClearBanned(); // needed for unit testing
|
||||
static bool IsBanned(CNetAddr ip);
|
||||
bool Misbehaving(int howmuch); // 1 == a little, 100 == a lot
|
||||
void copyStats(CNodeStats &stats);
|
||||
};
|
||||
|
||||
|
||||
@@ -599,15 +650,17 @@ public:
|
||||
inline void RelayInventory(const CInv& inv)
|
||||
{
|
||||
// Put on lists to offer to the other nodes
|
||||
CRITICAL_BLOCK(cs_vNodes)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
pnode->PushInventory(inv);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RelayMessage(const CInv& inv, const T& a)
|
||||
{
|
||||
CDataStream ss(SER_NETWORK);
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss.reserve(10000);
|
||||
ss << a;
|
||||
RelayMessage(inv, ss);
|
||||
@@ -616,8 +669,8 @@ void RelayMessage(const CInv& inv, const T& a)
|
||||
template<>
|
||||
inline void RelayMessage<>(const CInv& inv, const CDataStream& ss)
|
||||
{
|
||||
CRITICAL_BLOCK(cs_mapRelay)
|
||||
{
|
||||
LOCK(cs_mapRelay);
|
||||
// Expire old relay messages
|
||||
while (!vRelayExpiration.empty() && vRelayExpiration.front().first < GetTime())
|
||||
{
|
||||
@@ -626,7 +679,7 @@ inline void RelayMessage<>(const CInv& inv, const CDataStream& ss)
|
||||
}
|
||||
|
||||
// Save original serialized message so newer versions are preserved
|
||||
mapRelay[inv] = ss;
|
||||
mapRelay.insert(std::make_pair(inv, ss));
|
||||
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv));
|
||||
}
|
||||
|
||||
@@ -634,58 +687,4 @@ inline void RelayMessage<>(const CInv& inv, const CDataStream& ss)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Templates for the publish and subscription system.
|
||||
// The object being published as T& obj needs to have:
|
||||
// a set<unsigned int> setSources member
|
||||
// specializations of AdvertInsert and AdvertErase
|
||||
// Currently implemented for CTable and CProduct.
|
||||
//
|
||||
|
||||
template<typename T>
|
||||
void AdvertStartPublish(CNode* pfrom, unsigned int nChannel, unsigned int nHops, T& obj)
|
||||
{
|
||||
// Add to sources
|
||||
obj.setSources.insert(pfrom->addr.ip);
|
||||
|
||||
if (!AdvertInsert(obj))
|
||||
return;
|
||||
|
||||
// Relay
|
||||
CRITICAL_BLOCK(cs_vNodes)
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
if (pnode != pfrom && (nHops < PUBLISH_HOPS || pnode->IsSubscribed(nChannel)))
|
||||
pnode->PushMessage("publish", nChannel, nHops, obj);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AdvertStopPublish(CNode* pfrom, unsigned int nChannel, unsigned int nHops, T& obj)
|
||||
{
|
||||
uint256 hash = obj.GetHash();
|
||||
|
||||
CRITICAL_BLOCK(cs_vNodes)
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
if (pnode != pfrom && (nHops < PUBLISH_HOPS || pnode->IsSubscribed(nChannel)))
|
||||
pnode->PushMessage("pub-cancel", nChannel, nHops, hash);
|
||||
|
||||
AdvertErase(obj);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AdvertRemoveSource(CNode* pfrom, unsigned int nChannel, unsigned int nHops, T& obj)
|
||||
{
|
||||
// Remove a source
|
||||
obj.setSources.erase(pfrom->addr.ip);
|
||||
|
||||
// If no longer supported by any sources, cancel it
|
||||
if (obj.setSources.empty())
|
||||
AdvertStopPublish(pfrom, nChannel, nHops, obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
687
src/netbase.cpp
687
src/netbase.cpp
@@ -1,30 +1,72 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "netbase.h"
|
||||
#include "util.h"
|
||||
#include "sync.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "strlcpy.h"
|
||||
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Settings
|
||||
int fUseProxy = false;
|
||||
CService addrProxy("127.0.0.1",9050);
|
||||
static proxyType proxyInfo[NET_MAX];
|
||||
static proxyType nameproxyInfo;
|
||||
static CCriticalSection cs_proxyInfos;
|
||||
int nConnectTimeout = 5000;
|
||||
|
||||
bool fNameLookup = false;
|
||||
|
||||
static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
|
||||
|
||||
bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, int nMaxSolutions, bool fAllowLookup)
|
||||
enum Network ParseNetwork(std::string net) {
|
||||
boost::to_lower(net);
|
||||
if (net == "ipv4") return NET_IPV4;
|
||||
if (net == "ipv6") return NET_IPV6;
|
||||
if (net == "tor") return NET_TOR;
|
||||
if (net == "i2p") return NET_I2P;
|
||||
return NET_UNROUTABLE;
|
||||
}
|
||||
|
||||
void SplitHostPort(std::string in, int &portOut, std::string &hostOut) {
|
||||
size_t colon = in.find_last_of(':');
|
||||
// if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
|
||||
bool fHaveColon = colon != in.npos;
|
||||
bool fBracketed = fHaveColon && (in[0]=='[' && in[colon-1]==']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe
|
||||
bool fMultiColon = fHaveColon && (in.find_last_of(':',colon-1) != in.npos);
|
||||
if (fHaveColon && (colon==0 || fBracketed || !fMultiColon)) {
|
||||
char *endp = NULL;
|
||||
int n = strtol(in.c_str() + colon + 1, &endp, 10);
|
||||
if (endp && *endp == 0 && n >= 0) {
|
||||
in = in.substr(0, colon);
|
||||
if (n > 0 && n < 0x10000)
|
||||
portOut = n;
|
||||
}
|
||||
}
|
||||
if (in.size()>0 && in[0] == '[' && in[in.size()-1] == ']')
|
||||
hostOut = in.substr(1, in.size()-2);
|
||||
else
|
||||
hostOut = in;
|
||||
}
|
||||
|
||||
bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
|
||||
{
|
||||
vIP.clear();
|
||||
|
||||
{
|
||||
CNetAddr addr;
|
||||
if (addr.SetSpecial(std::string(pszName))) {
|
||||
vIP.push_back(addr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
struct addrinfo aiHint;
|
||||
memset(&aiHint, 0, sizeof(struct addrinfo));
|
||||
|
||||
@@ -33,19 +75,17 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, int nM
|
||||
#ifdef WIN32
|
||||
# ifdef USE_IPV6
|
||||
aiHint.ai_family = AF_UNSPEC;
|
||||
aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
|
||||
# else
|
||||
aiHint.ai_family = AF_INET;
|
||||
aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
|
||||
# endif
|
||||
aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
|
||||
#else
|
||||
# ifdef USE_IPV6
|
||||
aiHint.ai_family = AF_UNSPEC;
|
||||
aiHint.ai_flags = AI_ADDRCONFIG | (fAllowLookup ? 0 : AI_NUMERICHOST);
|
||||
# else
|
||||
aiHint.ai_family = AF_INET;
|
||||
aiHint.ai_flags = AI_ADDRCONFIG | (fAllowLookup ? 0 : AI_NUMERICHOST);
|
||||
# endif
|
||||
aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
|
||||
#endif
|
||||
struct addrinfo *aiRes = NULL;
|
||||
int nErr = getaddrinfo(pszName, NULL, &aiHint, &aiRes);
|
||||
@@ -77,7 +117,7 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, int nM
|
||||
return (vIP.size() > 0);
|
||||
}
|
||||
|
||||
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, int nMaxSolutions, bool fAllowLookup)
|
||||
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
|
||||
{
|
||||
if (pszName[0] == 0)
|
||||
return false;
|
||||
@@ -93,50 +133,25 @@ bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, int nMaxSolutio
|
||||
return LookupIntern(pszHost, vIP, nMaxSolutions, fAllowLookup);
|
||||
}
|
||||
|
||||
bool LookupHostNumeric(const char *pszName, std::vector<CNetAddr>& vIP, int nMaxSolutions)
|
||||
bool LookupHostNumeric(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions)
|
||||
{
|
||||
return LookupHost(pszName, vIP, nMaxSolutions, false);
|
||||
}
|
||||
|
||||
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, int nMaxSolutions)
|
||||
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
|
||||
{
|
||||
if (pszName[0] == 0)
|
||||
return false;
|
||||
int port = portDefault;
|
||||
char psz[256];
|
||||
char *pszHost = psz;
|
||||
strlcpy(psz, pszName, sizeof(psz));
|
||||
char* pszColon = strrchr(psz+1,':');
|
||||
char *pszPortEnd = NULL;
|
||||
int portParsed = pszColon ? strtoul(pszColon+1, &pszPortEnd, 10) : 0;
|
||||
if (pszColon && pszPortEnd && pszPortEnd[0] == 0)
|
||||
{
|
||||
if (psz[0] == '[' && pszColon[-1] == ']')
|
||||
{
|
||||
pszHost = psz+1;
|
||||
pszColon[-1] = 0;
|
||||
}
|
||||
else
|
||||
pszColon[0] = 0;
|
||||
if (port >= 0 && port <= USHRT_MAX)
|
||||
port = portParsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (psz[0] == '[' && psz[strlen(psz)-1] == ']')
|
||||
{
|
||||
pszHost = psz+1;
|
||||
psz[strlen(psz)-1] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
std::string hostname = "";
|
||||
SplitHostPort(std::string(pszName), port, hostname);
|
||||
|
||||
std::vector<CNetAddr> vIP;
|
||||
bool fRet = LookupIntern(pszHost, vIP, nMaxSolutions, fAllowLookup);
|
||||
bool fRet = LookupIntern(hostname.c_str(), vIP, nMaxSolutions, fAllowLookup);
|
||||
if (!fRet)
|
||||
return false;
|
||||
vAddr.resize(vIP.size());
|
||||
for (int i = 0; i < vIP.size(); i++)
|
||||
for (unsigned int i = 0; i < vIP.size(); i++)
|
||||
vAddr[i] = CService(vIP[i], port);
|
||||
return true;
|
||||
}
|
||||
@@ -156,11 +171,169 @@ bool LookupNumeric(const char *pszName, CService& addr, int portDefault)
|
||||
return Lookup(pszName, addr, portDefault, false);
|
||||
}
|
||||
|
||||
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
|
||||
bool static Socks4(const CService &addrDest, SOCKET& hSocket)
|
||||
{
|
||||
printf("SOCKS4 connecting %s\n", addrDest.ToString().c_str());
|
||||
if (!addrDest.IsIPv4())
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Proxy destination is not IPv4");
|
||||
}
|
||||
char pszSocks4IP[] = "\4\1\0\0\0\0\0\0user";
|
||||
struct sockaddr_in addr;
|
||||
socklen_t len = sizeof(addr);
|
||||
if (!addrDest.GetSockAddr((struct sockaddr*)&addr, &len) || addr.sin_family != AF_INET)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Cannot get proxy destination address");
|
||||
}
|
||||
memcpy(pszSocks4IP + 2, &addr.sin_port, 2);
|
||||
memcpy(pszSocks4IP + 4, &addr.sin_addr, 4);
|
||||
char* pszSocks4 = pszSocks4IP;
|
||||
int nSize = sizeof(pszSocks4IP);
|
||||
|
||||
int ret = send(hSocket, pszSocks4, nSize, MSG_NOSIGNAL);
|
||||
if (ret != nSize)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error sending to proxy");
|
||||
}
|
||||
char pchRet[8];
|
||||
if (recv(hSocket, pchRet, 8, 0) != 8)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error reading proxy response");
|
||||
}
|
||||
if (pchRet[1] != 0x5a)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
if (pchRet[1] != 0x5b)
|
||||
printf("ERROR: Proxy returned error %d\n", pchRet[1]);
|
||||
return false;
|
||||
}
|
||||
printf("SOCKS4 connected %s\n", addrDest.ToString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool static Socks5(string strDest, int port, SOCKET& hSocket)
|
||||
{
|
||||
printf("SOCKS5 connecting %s\n", strDest.c_str());
|
||||
if (strDest.size() > 255)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Hostname too long");
|
||||
}
|
||||
char pszSocks5Init[] = "\5\1\0";
|
||||
char *pszSocks5 = pszSocks5Init;
|
||||
ssize_t nSize = sizeof(pszSocks5Init) - 1;
|
||||
|
||||
ssize_t ret = send(hSocket, pszSocks5, nSize, MSG_NOSIGNAL);
|
||||
if (ret != nSize)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error sending to proxy");
|
||||
}
|
||||
char pchRet1[2];
|
||||
if (recv(hSocket, pchRet1, 2, 0) != 2)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error reading proxy response");
|
||||
}
|
||||
if (pchRet1[0] != 0x05 || pchRet1[1] != 0x00)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Proxy failed to initialize");
|
||||
}
|
||||
string strSocks5("\5\1");
|
||||
strSocks5 += '\000'; strSocks5 += '\003';
|
||||
strSocks5 += static_cast<char>(std::min((int)strDest.size(), 255));
|
||||
strSocks5 += strDest;
|
||||
strSocks5 += static_cast<char>((port >> 8) & 0xFF);
|
||||
strSocks5 += static_cast<char>((port >> 0) & 0xFF);
|
||||
ret = send(hSocket, strSocks5.c_str(), strSocks5.size(), MSG_NOSIGNAL);
|
||||
if (ret != (ssize_t)strSocks5.size())
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error sending to proxy");
|
||||
}
|
||||
char pchRet2[4];
|
||||
if (recv(hSocket, pchRet2, 4, 0) != 4)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error reading proxy response");
|
||||
}
|
||||
if (pchRet2[0] != 0x05)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Proxy failed to accept request");
|
||||
}
|
||||
if (pchRet2[1] != 0x00)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
switch (pchRet2[1])
|
||||
{
|
||||
case 0x01: return error("Proxy error: general failure");
|
||||
case 0x02: return error("Proxy error: connection not allowed");
|
||||
case 0x03: return error("Proxy error: network unreachable");
|
||||
case 0x04: return error("Proxy error: host unreachable");
|
||||
case 0x05: return error("Proxy error: connection refused");
|
||||
case 0x06: return error("Proxy error: TTL expired");
|
||||
case 0x07: return error("Proxy error: protocol error");
|
||||
case 0x08: return error("Proxy error: address type not supported");
|
||||
default: return error("Proxy error: unknown");
|
||||
}
|
||||
}
|
||||
if (pchRet2[2] != 0x00)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error: malformed proxy response");
|
||||
}
|
||||
char pchRet3[256];
|
||||
switch (pchRet2[3])
|
||||
{
|
||||
case 0x01: ret = recv(hSocket, pchRet3, 4, 0) != 4; break;
|
||||
case 0x04: ret = recv(hSocket, pchRet3, 16, 0) != 16; break;
|
||||
case 0x03:
|
||||
{
|
||||
ret = recv(hSocket, pchRet3, 1, 0) != 1;
|
||||
if (ret)
|
||||
return error("Error reading from proxy");
|
||||
int nRecv = pchRet3[0];
|
||||
ret = recv(hSocket, pchRet3, nRecv, 0) != nRecv;
|
||||
break;
|
||||
}
|
||||
default: closesocket(hSocket); return error("Error: malformed proxy response");
|
||||
}
|
||||
if (ret)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error reading from proxy");
|
||||
}
|
||||
if (recv(hSocket, pchRet3, 2, 0) != 2)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error reading from proxy");
|
||||
}
|
||||
printf("SOCKS5 connected %s\n", strDest.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRet, int nTimeout)
|
||||
{
|
||||
hSocketRet = INVALID_SOCKET;
|
||||
|
||||
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
#ifdef USE_IPV6
|
||||
struct sockaddr_storage sockaddr;
|
||||
#else
|
||||
struct sockaddr sockaddr;
|
||||
#endif
|
||||
socklen_t len = sizeof(sockaddr);
|
||||
if (!addrConnect.GetSockAddr((struct sockaddr*)&sockaddr, &len)) {
|
||||
printf("Cannot connect to %s: unsupported network\n", addrConnect.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
SOCKET hSocket = socket(((struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (hSocket == INVALID_SOCKET)
|
||||
return false;
|
||||
#ifdef SO_NOSIGPIPE
|
||||
@@ -168,13 +341,6 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
|
||||
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
||||
#endif
|
||||
|
||||
bool fProxy = (fUseProxy && addrDest.IsRoutable());
|
||||
struct sockaddr_in sockaddr;
|
||||
if (fProxy)
|
||||
addrProxy.GetSockAddr(&sockaddr);
|
||||
else
|
||||
addrDest.GetSockAddr(&sockaddr);
|
||||
|
||||
#ifdef WIN32
|
||||
u_long fNonblock = 1;
|
||||
if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
|
||||
@@ -187,8 +353,7 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (connect(hSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR)
|
||||
if (connect(hSocket, (struct sockaddr*)&sockaddr, len) == SOCKET_ERROR)
|
||||
{
|
||||
// WSAEINVAL is here because some legacy version of winsock uses it
|
||||
if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK || WSAGetLastError() == WSAEINVAL)
|
||||
@@ -258,37 +423,123 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fProxy)
|
||||
{
|
||||
printf("proxy connecting %s\n", addrDest.ToString().c_str());
|
||||
char pszSocks4IP[] = "\4\1\0\0\0\0\0\0user";
|
||||
struct sockaddr_in addr;
|
||||
addrDest.GetSockAddr(&addr);
|
||||
memcpy(pszSocks4IP + 2, &addr.sin_port, 2);
|
||||
memcpy(pszSocks4IP + 4, &addr.sin_addr, 4);
|
||||
char* pszSocks4 = pszSocks4IP;
|
||||
int nSize = sizeof(pszSocks4IP);
|
||||
hSocketRet = hSocket;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ret = send(hSocket, pszSocks4, nSize, MSG_NOSIGNAL);
|
||||
if (ret != nSize)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error sending to proxy");
|
||||
}
|
||||
char pchRet[8];
|
||||
if (recv(hSocket, pchRet, 8, 0) != 8)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
return error("Error reading proxy response");
|
||||
}
|
||||
if (pchRet[1] != 0x5a)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
if (pchRet[1] != 0x5b)
|
||||
printf("ERROR: Proxy returned error %d\n", pchRet[1]);
|
||||
bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion) {
|
||||
assert(net >= 0 && net < NET_MAX);
|
||||
if (nSocksVersion != 0 && nSocksVersion != 4 && nSocksVersion != 5)
|
||||
return false;
|
||||
if (nSocksVersion != 0 && !addrProxy.IsValid())
|
||||
return false;
|
||||
LOCK(cs_proxyInfos);
|
||||
proxyInfo[net] = std::make_pair(addrProxy, nSocksVersion);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetProxy(enum Network net, proxyType &proxyInfoOut) {
|
||||
assert(net >= 0 && net < NET_MAX);
|
||||
LOCK(cs_proxyInfos);
|
||||
if (!proxyInfo[net].second)
|
||||
return false;
|
||||
proxyInfoOut = proxyInfo[net];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetNameProxy(CService addrProxy, int nSocksVersion) {
|
||||
if (nSocksVersion != 0 && nSocksVersion != 5)
|
||||
return false;
|
||||
if (nSocksVersion != 0 && !addrProxy.IsValid())
|
||||
return false;
|
||||
LOCK(cs_proxyInfos);
|
||||
nameproxyInfo = std::make_pair(addrProxy, nSocksVersion);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetNameProxy(proxyType &nameproxyInfoOut) {
|
||||
LOCK(cs_proxyInfos);
|
||||
if (!nameproxyInfo.second)
|
||||
return false;
|
||||
nameproxyInfoOut = nameproxyInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HaveNameProxy() {
|
||||
LOCK(cs_proxyInfos);
|
||||
return nameproxyInfo.second != 0;
|
||||
}
|
||||
|
||||
bool IsProxy(const CNetAddr &addr) {
|
||||
LOCK(cs_proxyInfos);
|
||||
for (int i = 0; i < NET_MAX; i++) {
|
||||
if (proxyInfo[i].second && (addr == (CNetAddr)proxyInfo[i].first))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
|
||||
{
|
||||
proxyType proxy;
|
||||
|
||||
// no proxy needed
|
||||
if (!GetProxy(addrDest.GetNetwork(), proxy))
|
||||
return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);
|
||||
|
||||
SOCKET hSocket = INVALID_SOCKET;
|
||||
|
||||
// first connect to proxy server
|
||||
if (!ConnectSocketDirectly(proxy.first, hSocket, nTimeout))
|
||||
return false;
|
||||
|
||||
// do socks negotiation
|
||||
switch (proxy.second) {
|
||||
case 4:
|
||||
if (!Socks4(addrDest, hSocket))
|
||||
return false;
|
||||
}
|
||||
printf("proxy connected %s\n", addrDest.ToString().c_str());
|
||||
break;
|
||||
case 5:
|
||||
if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket))
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
hSocketRet = hSocket;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault, int nTimeout)
|
||||
{
|
||||
string strDest;
|
||||
int port = portDefault;
|
||||
SplitHostPort(string(pszDest), port, strDest);
|
||||
|
||||
SOCKET hSocket = INVALID_SOCKET;
|
||||
|
||||
proxyType nameproxy;
|
||||
GetNameProxy(nameproxy);
|
||||
|
||||
CService addrResolved(CNetAddr(strDest, fNameLookup && !nameproxy.second), port);
|
||||
if (addrResolved.IsValid()) {
|
||||
addr = addrResolved;
|
||||
return ConnectSocket(addr, hSocketRet, nTimeout);
|
||||
}
|
||||
addr = CService("0.0.0.0:0");
|
||||
if (!nameproxy.second)
|
||||
return false;
|
||||
if (!ConnectSocketDirectly(nameproxy.first, hSocket, nTimeout))
|
||||
return false;
|
||||
|
||||
switch(nameproxy.second) {
|
||||
default:
|
||||
case 4: return false;
|
||||
case 5:
|
||||
if (!Socks5(strDest, port, hSocket))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
hSocketRet = hSocket;
|
||||
@@ -305,6 +556,32 @@ void CNetAddr::SetIP(const CNetAddr& ipIn)
|
||||
memcpy(ip, ipIn.ip, sizeof(ip));
|
||||
}
|
||||
|
||||
static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43};
|
||||
static const unsigned char pchGarliCat[] = {0xFD,0x60,0xDB,0x4D,0xDD,0xB5};
|
||||
|
||||
bool CNetAddr::SetSpecial(const std::string &strName)
|
||||
{
|
||||
if (strName.size()>6 && strName.substr(strName.size() - 6, 6) == ".onion") {
|
||||
std::vector<unsigned char> vchAddr = DecodeBase32(strName.substr(0, strName.size() - 6).c_str());
|
||||
if (vchAddr.size() != 16-sizeof(pchOnionCat))
|
||||
return false;
|
||||
memcpy(ip, pchOnionCat, sizeof(pchOnionCat));
|
||||
for (unsigned int i=0; i<16-sizeof(pchOnionCat); i++)
|
||||
ip[i + sizeof(pchOnionCat)] = vchAddr[i];
|
||||
return true;
|
||||
}
|
||||
if (strName.size()>11 && strName.substr(strName.size() - 11, 11) == ".oc.b32.i2p") {
|
||||
std::vector<unsigned char> vchAddr = DecodeBase32(strName.substr(0, strName.size() - 11).c_str());
|
||||
if (vchAddr.size() != 16-sizeof(pchGarliCat))
|
||||
return false;
|
||||
memcpy(ip, pchOnionCat, sizeof(pchGarliCat));
|
||||
for (unsigned int i=0; i<16-sizeof(pchGarliCat); i++)
|
||||
ip[i + sizeof(pchGarliCat)] = vchAddr[i];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CNetAddr::CNetAddr()
|
||||
{
|
||||
Init();
|
||||
@@ -339,7 +616,7 @@ CNetAddr::CNetAddr(const std::string &strIp, bool fAllowLookup)
|
||||
*this = vIP[0];
|
||||
}
|
||||
|
||||
int CNetAddr::GetByte(int n) const
|
||||
unsigned int CNetAddr::GetByte(int n) const
|
||||
{
|
||||
return ip[15-n];
|
||||
}
|
||||
@@ -349,11 +626,16 @@ bool CNetAddr::IsIPv4() const
|
||||
return (memcmp(ip, pchIPv4, sizeof(pchIPv4)) == 0);
|
||||
}
|
||||
|
||||
bool CNetAddr::IsIPv6() const
|
||||
{
|
||||
return (!IsIPv4() && !IsTor() && !IsI2P());
|
||||
}
|
||||
|
||||
bool CNetAddr::IsRFC1918() const
|
||||
{
|
||||
return IsIPv4() && (
|
||||
GetByte(3) == 10 ||
|
||||
(GetByte(3) == 192 && GetByte(2) == 168) ||
|
||||
GetByte(3) == 10 ||
|
||||
(GetByte(3) == 192 && GetByte(2) == 168) ||
|
||||
(GetByte(3) == 172 && (GetByte(2) >= 16 && GetByte(2) <= 31)));
|
||||
}
|
||||
|
||||
@@ -405,6 +687,16 @@ bool CNetAddr::IsRFC4843() const
|
||||
return (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x00 && (GetByte(12) & 0xF0) == 0x10);
|
||||
}
|
||||
|
||||
bool CNetAddr::IsTor() const
|
||||
{
|
||||
return (memcmp(ip, pchOnionCat, sizeof(pchOnionCat)) == 0);
|
||||
}
|
||||
|
||||
bool CNetAddr::IsI2P() const
|
||||
{
|
||||
return (memcmp(ip, pchGarliCat, sizeof(pchGarliCat)) == 0);
|
||||
}
|
||||
|
||||
bool CNetAddr::IsLocal() const
|
||||
{
|
||||
// IPv4 loopback
|
||||
@@ -427,7 +719,7 @@ bool CNetAddr::IsMulticast() const
|
||||
|
||||
bool CNetAddr::IsValid() const
|
||||
{
|
||||
// Clean up 3-byte shifted addresses caused by garbage in size field
|
||||
// Cleanup 3-byte shifted addresses caused by garbage in size field
|
||||
// of addr messages from versions before 0.2.9 checksum.
|
||||
// Two consecutive addr messages look like this:
|
||||
// header20 vectorlen3 addr26 addr26 addr26 header20 vectorlen3 addr26 addr26 addr26...
|
||||
@@ -463,11 +755,44 @@ bool CNetAddr::IsValid() const
|
||||
|
||||
bool CNetAddr::IsRoutable() const
|
||||
{
|
||||
return IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || IsRFC4193() || IsRFC4843() || IsLocal());
|
||||
return IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || (IsRFC4193() && !IsTor() && !IsI2P()) || IsRFC4843() || IsLocal());
|
||||
}
|
||||
|
||||
enum Network CNetAddr::GetNetwork() const
|
||||
{
|
||||
if (!IsRoutable())
|
||||
return NET_UNROUTABLE;
|
||||
|
||||
if (IsIPv4())
|
||||
return NET_IPV4;
|
||||
|
||||
if (IsTor())
|
||||
return NET_TOR;
|
||||
|
||||
if (IsI2P())
|
||||
return NET_I2P;
|
||||
|
||||
return NET_IPV6;
|
||||
}
|
||||
|
||||
std::string CNetAddr::ToStringIP() const
|
||||
{
|
||||
if (IsTor())
|
||||
return EncodeBase32(&ip[6], 10) + ".onion";
|
||||
if (IsI2P())
|
||||
return EncodeBase32(&ip[6], 10) + ".oc.b32.i2p";
|
||||
CService serv(*this, 0);
|
||||
#ifdef USE_IPV6
|
||||
struct sockaddr_storage sockaddr;
|
||||
#else
|
||||
struct sockaddr sockaddr;
|
||||
#endif
|
||||
socklen_t socklen = sizeof(sockaddr);
|
||||
if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) {
|
||||
char name[1025] = "";
|
||||
if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST))
|
||||
return std::string(name);
|
||||
}
|
||||
if (IsIPv4())
|
||||
return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
|
||||
else
|
||||
@@ -519,37 +844,56 @@ bool CNetAddr::GetIn6Addr(struct in6_addr* pipv6Addr) const
|
||||
std::vector<unsigned char> CNetAddr::GetGroup() const
|
||||
{
|
||||
std::vector<unsigned char> vchRet;
|
||||
int nClass = 0; // 0=IPv6, 1=IPv4, 255=unroutable
|
||||
int nClass = NET_IPV6;
|
||||
int nStartByte = 0;
|
||||
int nBits = 16;
|
||||
|
||||
// for unroutable addresses, each address is considered different
|
||||
if (!IsRoutable())
|
||||
// all local addresses belong to the same group
|
||||
if (IsLocal())
|
||||
{
|
||||
nClass = 255;
|
||||
nBits = 128;
|
||||
nBits = 0;
|
||||
}
|
||||
|
||||
// all unroutable addresses belong to the same group
|
||||
if (!IsRoutable())
|
||||
{
|
||||
nClass = NET_UNROUTABLE;
|
||||
nBits = 0;
|
||||
}
|
||||
// for IPv4 addresses, '1' + the 16 higher-order bits of the IP
|
||||
// includes mapped IPv4, SIIT translated IPv4, and the well-known prefix
|
||||
else if (IsIPv4() || IsRFC6145() || IsRFC6052())
|
||||
{
|
||||
nClass = 1;
|
||||
nClass = NET_IPV4;
|
||||
nStartByte = 12;
|
||||
}
|
||||
// for 6to4 tunneled addresses, use the encapsulated IPv4 address
|
||||
// for 6to4 tunnelled addresses, use the encapsulated IPv4 address
|
||||
else if (IsRFC3964())
|
||||
{
|
||||
nClass = 1;
|
||||
nClass = NET_IPV4;
|
||||
nStartByte = 2;
|
||||
}
|
||||
// for Teredo-tunneled IPv6 addresses, use the encapsulated IPv4 address
|
||||
// for Teredo-tunnelled IPv6 addresses, use the encapsulated IPv4 address
|
||||
else if (IsRFC4380())
|
||||
{
|
||||
vchRet.push_back(1);
|
||||
vchRet.push_back(NET_IPV4);
|
||||
vchRet.push_back(GetByte(3) ^ 0xFF);
|
||||
vchRet.push_back(GetByte(2) ^ 0xFF);
|
||||
return vchRet;
|
||||
}
|
||||
else if (IsTor())
|
||||
{
|
||||
nClass = NET_TOR;
|
||||
nStartByte = 6;
|
||||
nBits = 4;
|
||||
}
|
||||
else if (IsI2P())
|
||||
{
|
||||
nClass = NET_I2P;
|
||||
nStartByte = 6;
|
||||
nBits = 4;
|
||||
}
|
||||
// for he.net, use /36 groups
|
||||
else if (GetByte(15) == 0x20 && GetByte(14) == 0x11 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
|
||||
nBits = 36;
|
||||
@@ -570,10 +914,10 @@ std::vector<unsigned char> CNetAddr::GetGroup() const
|
||||
return vchRet;
|
||||
}
|
||||
|
||||
int64 CNetAddr::GetHash() const
|
||||
uint64 CNetAddr::GetHash() const
|
||||
{
|
||||
uint256 hash = Hash(&ip[0], &ip[16]);
|
||||
int64 nRet;
|
||||
uint64 nRet;
|
||||
memcpy(&nRet, &hash, sizeof(nRet));
|
||||
return nRet;
|
||||
}
|
||||
@@ -583,6 +927,84 @@ void CNetAddr::print() const
|
||||
printf("CNetAddr(%s)\n", ToString().c_str());
|
||||
}
|
||||
|
||||
// private extensions to enum Network, only returned by GetExtNetwork,
|
||||
// and only used in GetReachabilityFrom
|
||||
static const int NET_UNKNOWN = NET_MAX + 0;
|
||||
static const int NET_TEREDO = NET_MAX + 1;
|
||||
int static GetExtNetwork(const CNetAddr *addr)
|
||||
{
|
||||
if (addr == NULL)
|
||||
return NET_UNKNOWN;
|
||||
if (addr->IsRFC4380())
|
||||
return NET_TEREDO;
|
||||
return addr->GetNetwork();
|
||||
}
|
||||
|
||||
/** Calculates a metric for how reachable (*this) is from a given partner */
|
||||
int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
|
||||
{
|
||||
enum Reachability {
|
||||
REACH_UNREACHABLE,
|
||||
REACH_DEFAULT,
|
||||
REACH_TEREDO,
|
||||
REACH_IPV6_WEAK,
|
||||
REACH_IPV4,
|
||||
REACH_IPV6_STRONG,
|
||||
REACH_PRIVATE
|
||||
};
|
||||
|
||||
if (!IsRoutable())
|
||||
return REACH_UNREACHABLE;
|
||||
|
||||
int ourNet = GetExtNetwork(this);
|
||||
int theirNet = GetExtNetwork(paddrPartner);
|
||||
bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
|
||||
|
||||
switch(theirNet) {
|
||||
case NET_IPV4:
|
||||
switch(ourNet) {
|
||||
default: return REACH_DEFAULT;
|
||||
case NET_IPV4: return REACH_IPV4;
|
||||
}
|
||||
case NET_IPV6:
|
||||
switch(ourNet) {
|
||||
default: return REACH_DEFAULT;
|
||||
case NET_TEREDO: return REACH_TEREDO;
|
||||
case NET_IPV4: return REACH_IPV4;
|
||||
case NET_IPV6: return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG; // only prefer giving our IPv6 address if it's not tunnelled
|
||||
}
|
||||
case NET_TOR:
|
||||
switch(ourNet) {
|
||||
default: return REACH_DEFAULT;
|
||||
case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well
|
||||
case NET_TOR: return REACH_PRIVATE;
|
||||
}
|
||||
case NET_I2P:
|
||||
switch(ourNet) {
|
||||
default: return REACH_DEFAULT;
|
||||
case NET_I2P: return REACH_PRIVATE;
|
||||
}
|
||||
case NET_TEREDO:
|
||||
switch(ourNet) {
|
||||
default: return REACH_DEFAULT;
|
||||
case NET_TEREDO: return REACH_TEREDO;
|
||||
case NET_IPV6: return REACH_IPV6_WEAK;
|
||||
case NET_IPV4: return REACH_IPV4;
|
||||
}
|
||||
case NET_UNKNOWN:
|
||||
case NET_UNROUTABLE:
|
||||
default:
|
||||
switch(ourNet) {
|
||||
default: return REACH_DEFAULT;
|
||||
case NET_TEREDO: return REACH_TEREDO;
|
||||
case NET_IPV6: return REACH_IPV6_WEAK;
|
||||
case NET_IPV4: return REACH_IPV4;
|
||||
case NET_I2P: return REACH_PRIVATE; // assume connections from unroutable addresses are
|
||||
case NET_TOR: return REACH_PRIVATE; // either from Tor/I2P, or don't care about our address
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CService::Init()
|
||||
{
|
||||
port = 0;
|
||||
@@ -619,6 +1041,22 @@ CService::CService(const struct sockaddr_in6 &addr) : CNetAddr(addr.sin6_addr),
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CService::SetSockAddr(const struct sockaddr *paddr)
|
||||
{
|
||||
switch (paddr->sa_family) {
|
||||
case AF_INET:
|
||||
*this = CService(*(const struct sockaddr_in*)paddr);
|
||||
return true;
|
||||
#ifdef USE_IPV6
|
||||
case AF_INET6:
|
||||
*this = CService(*(const struct sockaddr_in6*)paddr);
|
||||
return true;
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
CService::CService(const char *pszIpPort, bool fAllowLookup)
|
||||
{
|
||||
Init();
|
||||
@@ -671,29 +1109,36 @@ bool operator<(const CService& a, const CService& b)
|
||||
return (CNetAddr)a < (CNetAddr)b || ((CNetAddr)a == (CNetAddr)b && a.port < b.port);
|
||||
}
|
||||
|
||||
bool CService::GetSockAddr(struct sockaddr_in* paddr) const
|
||||
bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
|
||||
{
|
||||
if (!IsIPv4())
|
||||
return false;
|
||||
memset(paddr, 0, sizeof(struct sockaddr_in));
|
||||
if (!GetInAddr(&paddr->sin_addr))
|
||||
return false;
|
||||
paddr->sin_family = AF_INET;
|
||||
paddr->sin_port = htons(port);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsIPv4()) {
|
||||
if (*addrlen < (socklen_t)sizeof(struct sockaddr_in))
|
||||
return false;
|
||||
*addrlen = sizeof(struct sockaddr_in);
|
||||
struct sockaddr_in *paddrin = (struct sockaddr_in*)paddr;
|
||||
memset(paddrin, 0, *addrlen);
|
||||
if (!GetInAddr(&paddrin->sin_addr))
|
||||
return false;
|
||||
paddrin->sin_family = AF_INET;
|
||||
paddrin->sin_port = htons(port);
|
||||
return true;
|
||||
}
|
||||
#ifdef USE_IPV6
|
||||
bool CService::GetSockAddr6(struct sockaddr_in6* paddr) const
|
||||
{
|
||||
memset(paddr, 0, sizeof(struct sockaddr_in6));
|
||||
if (!GetIn6Addr(&paddr->sin6_addr))
|
||||
return false;
|
||||
paddr->sin6_family = AF_INET6;
|
||||
paddr->sin6_port = htons(port);
|
||||
return true;
|
||||
}
|
||||
if (IsIPv6()) {
|
||||
if (*addrlen < (socklen_t)sizeof(struct sockaddr_in6))
|
||||
return false;
|
||||
*addrlen = sizeof(struct sockaddr_in6);
|
||||
struct sockaddr_in6 *paddrin6 = (struct sockaddr_in6*)paddr;
|
||||
memset(paddrin6, 0, *addrlen);
|
||||
if (!GetIn6Addr(&paddrin6->sin6_addr))
|
||||
return false;
|
||||
paddrin6->sin6_family = AF_INET6;
|
||||
paddrin6->sin6_port = htons(port);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> CService::GetKey() const
|
||||
{
|
||||
@@ -707,12 +1152,16 @@ std::vector<unsigned char> CService::GetKey() const
|
||||
|
||||
std::string CService::ToStringPort() const
|
||||
{
|
||||
return strprintf(":%i", port);
|
||||
return strprintf("%u", port);
|
||||
}
|
||||
|
||||
std::string CService::ToStringIPPort() const
|
||||
{
|
||||
return ToStringIP() + ToStringPort();
|
||||
if (IsIPv4() || IsTor() || IsI2P()) {
|
||||
return ToStringIP() + ":" + ToStringPort();
|
||||
} else {
|
||||
return "[" + ToStringIP() + "]:" + ToStringPort();
|
||||
}
|
||||
}
|
||||
|
||||
std::string CService::ToString() const
|
||||
|
||||
@@ -1,36 +1,37 @@
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_NETBASE_H
|
||||
#define BITCOIN_NETBASE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef WIN32
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <winsock2.h>
|
||||
#include <mswsock.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
#ifdef BSD
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "serialize.h"
|
||||
#include "compat.h"
|
||||
|
||||
extern int nConnectTimeout;
|
||||
|
||||
#ifdef WIN32
|
||||
// In MSVC, this is defined as a macro, undefine it to prevent a compile and link error
|
||||
#undef SetPort
|
||||
#endif
|
||||
|
||||
// IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
|
||||
enum Network
|
||||
{
|
||||
NET_UNROUTABLE,
|
||||
NET_IPV4,
|
||||
NET_IPV6,
|
||||
NET_TOR,
|
||||
NET_I2P,
|
||||
|
||||
NET_MAX,
|
||||
};
|
||||
|
||||
extern int nConnectTimeout;
|
||||
extern bool fNameLookup;
|
||||
|
||||
/** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */
|
||||
class CNetAddr
|
||||
{
|
||||
protected:
|
||||
@@ -43,27 +44,33 @@ class CNetAddr
|
||||
explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false);
|
||||
void Init();
|
||||
void SetIP(const CNetAddr& ip);
|
||||
bool SetSpecial(const std::string &strName); // for Tor and I2P addresses
|
||||
bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
|
||||
bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor/I2P)
|
||||
bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
|
||||
bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
|
||||
bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
|
||||
bool IsRFC3964() const; // IPv6 6to4 tunneling (2002::/16)
|
||||
bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
|
||||
bool IsRFC4193() const; // IPv6 unique local (FC00::/15)
|
||||
bool IsRFC4380() const; // IPv6 Teredo tunneling (2001::/32)
|
||||
bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
|
||||
bool IsRFC4843() const; // IPv6 ORCHID (2001:10::/28)
|
||||
bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
|
||||
bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96)
|
||||
bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96)
|
||||
bool IsTor() const;
|
||||
bool IsI2P() const;
|
||||
bool IsLocal() const;
|
||||
bool IsRoutable() const;
|
||||
bool IsValid() const;
|
||||
bool IsMulticast() const;
|
||||
enum Network GetNetwork() const;
|
||||
std::string ToString() const;
|
||||
std::string ToStringIP() const;
|
||||
int GetByte(int n) const;
|
||||
int64 GetHash() const;
|
||||
unsigned int GetByte(int n) const;
|
||||
uint64 GetHash() const;
|
||||
bool GetInAddr(struct in_addr* pipv4Addr) const;
|
||||
std::vector<unsigned char> GetGroup() const;
|
||||
int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const;
|
||||
void print() const;
|
||||
|
||||
#ifdef USE_IPV6
|
||||
@@ -81,6 +88,7 @@ class CNetAddr
|
||||
)
|
||||
};
|
||||
|
||||
/** A combination of a network address (CNetAddr) and a (TCP) port */
|
||||
class CService : public CNetAddr
|
||||
{
|
||||
protected:
|
||||
@@ -98,7 +106,8 @@ class CService : public CNetAddr
|
||||
void Init();
|
||||
void SetPort(unsigned short portIn);
|
||||
unsigned short GetPort() const;
|
||||
bool GetSockAddr(struct sockaddr_in* paddr) const;
|
||||
bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const;
|
||||
bool SetSockAddr(const struct sockaddr* paddr);
|
||||
friend bool operator==(const CService& a, const CService& b);
|
||||
friend bool operator!=(const CService& a, const CService& b);
|
||||
friend bool operator<(const CService& a, const CService& b);
|
||||
@@ -110,7 +119,6 @@ class CService : public CNetAddr
|
||||
|
||||
#ifdef USE_IPV6
|
||||
CService(const struct in6_addr& ipv6Addr, unsigned short port);
|
||||
bool GetSockAddr6(struct sockaddr_in6* paddr) const;
|
||||
CService(const struct sockaddr_in6& addr);
|
||||
#endif
|
||||
|
||||
@@ -125,15 +133,21 @@ class CService : public CNetAddr
|
||||
)
|
||||
};
|
||||
|
||||
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, int nMaxSolutions = 0, bool fAllowLookup = true);
|
||||
bool LookupHostNumeric(const char *pszName, std::vector<CNetAddr>& vIP, int nMaxSolutions = 0);
|
||||
typedef std::pair<CService, int> proxyType;
|
||||
|
||||
enum Network ParseNetwork(std::string net);
|
||||
void SplitHostPort(std::string in, int &portOut, std::string &hostOut);
|
||||
bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion = 5);
|
||||
bool GetProxy(enum Network net, proxyType &proxyInfoOut);
|
||||
bool IsProxy(const CNetAddr &addr);
|
||||
bool SetNameProxy(CService addrProxy, int nSocksVersion = 5);
|
||||
bool HaveNameProxy();
|
||||
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions = 0, bool fAllowLookup = true);
|
||||
bool LookupHostNumeric(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions = 0);
|
||||
bool Lookup(const char *pszName, CService& addr, int portDefault = 0, bool fAllowLookup = true);
|
||||
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault = 0, bool fAllowLookup = true, int nMaxSolutions = 0);
|
||||
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault = 0, bool fAllowLookup = true, unsigned int nMaxSolutions = 0);
|
||||
bool LookupNumeric(const char *pszName, CService& addr, int portDefault = 0);
|
||||
bool ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout = nConnectTimeout);
|
||||
|
||||
// Settings
|
||||
extern int fUseProxy;
|
||||
extern CService addrProxy;
|
||||
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault = 0, int nTimeout = nConnectTimeout);
|
||||
|
||||
#endif
|
||||
|
||||
28
src/noui.cpp
Normal file
28
src/noui.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#include "ui_interface.h"
|
||||
#include "init.h"
|
||||
#include "bitcoinrpc.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
static int noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style)
|
||||
{
|
||||
printf("%s: %s\n", caption.c_str(), message.c_str());
|
||||
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
|
||||
return 4;
|
||||
}
|
||||
|
||||
static bool noui_ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void noui_connect()
|
||||
{
|
||||
// Connect bitcoind signal handlers
|
||||
uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox);
|
||||
uiInterface.ThreadSafeAskFee.connect(noui_ThreadSafeAskFee);
|
||||
}
|
||||
74
src/noui.h
74
src/noui.h
@@ -1,74 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_NOUI_H
|
||||
#define BITCOIN_NOUI_H
|
||||
|
||||
#include <string>
|
||||
#include <boost/function.hpp>
|
||||
#include "wallet.h"
|
||||
|
||||
typedef void wxWindow;
|
||||
#define wxYES 0x00000002
|
||||
#define wxOK 0x00000004
|
||||
#define wxNO 0x00000008
|
||||
#define wxYES_NO (wxYES|wxNO)
|
||||
#define wxCANCEL 0x00000010
|
||||
#define wxAPPLY 0x00000020
|
||||
#define wxCLOSE 0x00000040
|
||||
#define wxOK_DEFAULT 0x00000000
|
||||
#define wxYES_DEFAULT 0x00000000
|
||||
#define wxNO_DEFAULT 0x00000080
|
||||
#define wxCANCEL_DEFAULT 0x80000000
|
||||
#define wxICON_EXCLAMATION 0x00000100
|
||||
#define wxICON_HAND 0x00000200
|
||||
#define wxICON_WARNING wxICON_EXCLAMATION
|
||||
#define wxICON_ERROR wxICON_HAND
|
||||
#define wxICON_QUESTION 0x00000400
|
||||
#define wxICON_INFORMATION 0x00000800
|
||||
#define wxICON_STOP wxICON_HAND
|
||||
#define wxICON_ASTERISK wxICON_INFORMATION
|
||||
#define wxICON_MASK (0x00000100|0x00000200|0x00000400|0x00000800)
|
||||
#define wxFORWARD 0x00001000
|
||||
#define wxBACKWARD 0x00002000
|
||||
#define wxRESET 0x00004000
|
||||
#define wxHELP 0x00008000
|
||||
#define wxMORE 0x00010000
|
||||
#define wxSETUP 0x00020000
|
||||
|
||||
inline int MyMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
|
||||
{
|
||||
printf("%s: %s\n", caption.c_str(), message.c_str());
|
||||
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
|
||||
return 4;
|
||||
}
|
||||
#define wxMessageBox MyMessageBox
|
||||
|
||||
inline int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
|
||||
{
|
||||
return MyMessageBox(message, caption, style, parent, x, y);
|
||||
}
|
||||
|
||||
inline bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void CalledSetStatusBar(const std::string& strText, int nField)
|
||||
{
|
||||
}
|
||||
|
||||
inline void UIThreadCall(boost::function0<void> fn)
|
||||
{
|
||||
}
|
||||
|
||||
inline void MainFrameRepaint()
|
||||
{
|
||||
}
|
||||
|
||||
inline void InitMessage(const std::string &message)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
2
src/obj/nogui/.gitignore
vendored
2
src/obj/nogui/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
src/obj/test/.gitignore
vendored
2
src/obj/test/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "protocol.h"
|
||||
#include "util.h"
|
||||
@@ -107,7 +107,7 @@ CInv::CInv(int typeIn, const uint256& hashIn)
|
||||
|
||||
CInv::CInv(const std::string& strType, const uint256& hashIn)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
for (i = 1; i < ARRAYLEN(ppszTypeName); i++)
|
||||
{
|
||||
if (strType == ppszTypeName[i])
|
||||
@@ -128,7 +128,7 @@ bool operator<(const CInv& a, const CInv& b)
|
||||
|
||||
bool CInv::IsKnownType() const
|
||||
{
|
||||
return (type >= 1 && type < ARRAYLEN(ppszTypeName));
|
||||
return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
|
||||
}
|
||||
|
||||
const char* CInv::GetCommand() const
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This header can only be compiled as C++.
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "serialize.h"
|
||||
#include "netbase.h"
|
||||
#include "util.h"
|
||||
#include <string>
|
||||
#include "uint256.h"
|
||||
|
||||
@@ -22,15 +21,15 @@ static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
|
||||
return testnet ? 18333 : 8333;
|
||||
}
|
||||
|
||||
//
|
||||
// Message header
|
||||
// (4) message start
|
||||
// (12) command
|
||||
// (4) size
|
||||
// (4) checksum
|
||||
|
||||
extern unsigned char pchMessageStart[4];
|
||||
|
||||
/** Message header.
|
||||
* (4) message start.
|
||||
* (12) command.
|
||||
* (4) size.
|
||||
* (4) checksum.
|
||||
*/
|
||||
class CMessageHeader
|
||||
{
|
||||
public:
|
||||
@@ -50,18 +49,28 @@ class CMessageHeader
|
||||
|
||||
// TODO: make private (improves encapsulation)
|
||||
public:
|
||||
enum { COMMAND_SIZE=12 };
|
||||
char pchMessageStart[sizeof(::pchMessageStart)];
|
||||
enum {
|
||||
MESSAGE_START_SIZE=sizeof(::pchMessageStart),
|
||||
COMMAND_SIZE=12,
|
||||
MESSAGE_SIZE_SIZE=sizeof(int),
|
||||
CHECKSUM_SIZE=sizeof(int),
|
||||
|
||||
MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
|
||||
CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
|
||||
};
|
||||
char pchMessageStart[MESSAGE_START_SIZE];
|
||||
char pchCommand[COMMAND_SIZE];
|
||||
unsigned int nMessageSize;
|
||||
unsigned int nChecksum;
|
||||
};
|
||||
|
||||
/** nServices flags */
|
||||
enum
|
||||
{
|
||||
NODE_NETWORK = (1 << 0),
|
||||
};
|
||||
|
||||
/** A CService with information about it as peer */
|
||||
class CAddress : public CService
|
||||
{
|
||||
public:
|
||||
@@ -77,9 +86,10 @@ class CAddress : public CService
|
||||
if (fRead)
|
||||
pthis->Init();
|
||||
if (nType & SER_DISK)
|
||||
READWRITE(nVersion);
|
||||
if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
|
||||
READWRITE(nTime);
|
||||
READWRITE(nVersion);
|
||||
if ((nType & SER_DISK) ||
|
||||
(nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
|
||||
READWRITE(nTime);
|
||||
READWRITE(nServices);
|
||||
READWRITE(*pip);
|
||||
)
|
||||
@@ -94,9 +104,10 @@ class CAddress : public CService
|
||||
unsigned int nTime;
|
||||
|
||||
// memory only
|
||||
unsigned int nLastTry;
|
||||
int64 nLastTry;
|
||||
};
|
||||
|
||||
/** inv message data */
|
||||
class CInv
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "ui_aboutdialog.h"
|
||||
#include "clientmodel.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
AboutDialog::AboutDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AboutDialog)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ui_addressbookpage.h"
|
||||
|
||||
#include "addresstablemodel.h"
|
||||
#include "optionsmodel.h"
|
||||
#include "bitcoingui.h"
|
||||
#include "editaddressdialog.h"
|
||||
#include "csvmodelwriter.h"
|
||||
@@ -20,12 +21,13 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AddressBookPage),
|
||||
model(0),
|
||||
optionsModel(0),
|
||||
mode(mode),
|
||||
tab(tab)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
#ifdef Q_WS_MAC // Icons on push buttons are very uncommon on Mac
|
||||
#ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
|
||||
ui->newAddressButton->setIcon(QIcon());
|
||||
ui->copyToClipboard->setIcon(QIcon());
|
||||
ui->deleteButton->setIcon(QIcon());
|
||||
@@ -43,36 +45,53 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
|
||||
ui->tableView->setFocus();
|
||||
break;
|
||||
case ForEditing:
|
||||
ui->buttonBox->hide();
|
||||
ui->buttonBox->setVisible(false);
|
||||
break;
|
||||
}
|
||||
switch(tab)
|
||||
{
|
||||
case SendingTab:
|
||||
ui->labelExplanation->hide();
|
||||
ui->labelExplanation->setVisible(false);
|
||||
ui->deleteButton->setVisible(true);
|
||||
ui->signMessage->setVisible(false);
|
||||
break;
|
||||
case ReceivingTab:
|
||||
ui->deleteButton->setVisible(false);
|
||||
ui->signMessage->setVisible(true);
|
||||
break;
|
||||
}
|
||||
ui->tableView->setTabKeyNavigation(false);
|
||||
ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
// Context menu actions
|
||||
QAction *copyAddressAction = new QAction(tr("Copy address"), this);
|
||||
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
|
||||
QAction *editAction = new QAction(tr("Edit"), this);
|
||||
deleteAction = new QAction(tr("Delete"), this);
|
||||
QAction *copyLabelAction = new QAction(tr("Copy &Label"), this);
|
||||
QAction *copyAddressAction = new QAction(ui->copyToClipboard->text(), this);
|
||||
QAction *editAction = new QAction(tr("&Edit"), this);
|
||||
QAction *showQRCodeAction = new QAction(ui->showQRCode->text(), this);
|
||||
QAction *signMessageAction = new QAction(ui->signMessage->text(), this);
|
||||
QAction *verifyMessageAction = new QAction(ui->verifyMessage->text(), this);
|
||||
deleteAction = new QAction(ui->deleteButton->text(), this);
|
||||
|
||||
// Build context menu
|
||||
contextMenu = new QMenu();
|
||||
contextMenu->addAction(copyAddressAction);
|
||||
contextMenu->addAction(copyLabelAction);
|
||||
contextMenu->addAction(editAction);
|
||||
contextMenu->addAction(deleteAction);
|
||||
if(tab == SendingTab)
|
||||
contextMenu->addAction(deleteAction);
|
||||
contextMenu->addSeparator();
|
||||
contextMenu->addAction(showQRCodeAction);
|
||||
if(tab == ReceivingTab)
|
||||
contextMenu->addAction(signMessageAction);
|
||||
else if(tab == SendingTab)
|
||||
contextMenu->addAction(verifyMessageAction);
|
||||
|
||||
// Connect signals for context menu actions
|
||||
connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyToClipboard_clicked()));
|
||||
connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(onCopyLabelAction()));
|
||||
connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction()));
|
||||
connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteButton_clicked()));
|
||||
connect(showQRCodeAction, SIGNAL(triggered()), this, SLOT(on_showQRCode_clicked()));
|
||||
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(on_signMessage_clicked()));
|
||||
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(on_verifyMessage_clicked()));
|
||||
|
||||
connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint)));
|
||||
|
||||
@@ -90,12 +109,12 @@ void AddressBookPage::setModel(AddressTableModel *model)
|
||||
this->model = model;
|
||||
if(!model)
|
||||
return;
|
||||
// Refresh list from core
|
||||
model->updateList();
|
||||
|
||||
proxyModel = new QSortFilterProxyModel(this);
|
||||
proxyModel->setSourceModel(model);
|
||||
proxyModel->setDynamicSortFilter(true);
|
||||
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
switch(tab)
|
||||
{
|
||||
case ReceivingTab:
|
||||
@@ -121,18 +140,23 @@ void AddressBookPage::setModel(AddressTableModel *model)
|
||||
connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
||||
this, SLOT(selectionChanged()));
|
||||
|
||||
if(mode == ForSending)
|
||||
{
|
||||
// Auto-select first row when in sending mode
|
||||
ui->tableView->selectRow(0);
|
||||
}
|
||||
// Select row for newly created address
|
||||
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
||||
this, SLOT(selectNewAddress(QModelIndex,int,int)));
|
||||
|
||||
selectionChanged();
|
||||
}
|
||||
|
||||
void AddressBookPage::setOptionsModel(OptionsModel *optionsModel)
|
||||
{
|
||||
this->optionsModel = optionsModel;
|
||||
}
|
||||
|
||||
void AddressBookPage::on_copyToClipboard_clicked()
|
||||
{
|
||||
GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Address);
|
||||
}
|
||||
|
||||
void AddressBookPage::onCopyLabelAction()
|
||||
{
|
||||
GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Label);
|
||||
@@ -168,10 +192,22 @@ void AddressBookPage::on_signMessage_clicked()
|
||||
addr = address.toString();
|
||||
}
|
||||
|
||||
QObject *qoGUI = parent()->parent();
|
||||
BitcoinGUI *gui = qobject_cast<BitcoinGUI *>(qoGUI);
|
||||
if (gui)
|
||||
gui->gotoMessagePage(addr);
|
||||
emit signMessage(addr);
|
||||
}
|
||||
|
||||
void AddressBookPage::on_verifyMessage_clicked()
|
||||
{
|
||||
QTableView *table = ui->tableView;
|
||||
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
|
||||
QString addr;
|
||||
|
||||
foreach (QModelIndex index, indexes)
|
||||
{
|
||||
QVariant address = index.data();
|
||||
addr = address.toString();
|
||||
}
|
||||
|
||||
emit verifyMessage(addr);
|
||||
}
|
||||
|
||||
void AddressBookPage::on_newAddressButton_clicked()
|
||||
@@ -181,20 +217,11 @@ void AddressBookPage::on_newAddressButton_clicked()
|
||||
EditAddressDialog dlg(
|
||||
tab == SendingTab ?
|
||||
EditAddressDialog::NewSendingAddress :
|
||||
EditAddressDialog::NewReceivingAddress);
|
||||
EditAddressDialog::NewReceivingAddress, this);
|
||||
dlg.setModel(model);
|
||||
if(dlg.exec())
|
||||
{
|
||||
// Select row for newly created address
|
||||
QString address = dlg.getAddress();
|
||||
QModelIndexList lst = proxyModel->match(proxyModel->index(0,
|
||||
AddressTableModel::Address, QModelIndex()),
|
||||
Qt::EditRole, address, 1, Qt::MatchExactly);
|
||||
if(!lst.isEmpty())
|
||||
{
|
||||
ui->tableView->setFocus();
|
||||
ui->tableView->selectRow(lst.at(0).row());
|
||||
}
|
||||
newAddressToSelect = dlg.getAddress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,14 +251,22 @@ void AddressBookPage::selectionChanged()
|
||||
case SendingTab:
|
||||
// In sending tab, allow deletion of selection
|
||||
ui->deleteButton->setEnabled(true);
|
||||
ui->deleteButton->setVisible(true);
|
||||
deleteAction->setEnabled(true);
|
||||
ui->signMessage->setEnabled(false);
|
||||
ui->signMessage->setVisible(false);
|
||||
ui->verifyMessage->setEnabled(true);
|
||||
ui->verifyMessage->setVisible(true);
|
||||
break;
|
||||
case ReceivingTab:
|
||||
// Deleting receiving addresses, however, is not allowed
|
||||
ui->deleteButton->setEnabled(false);
|
||||
ui->deleteButton->setVisible(false);
|
||||
deleteAction->setEnabled(false);
|
||||
ui->signMessage->setEnabled(true);
|
||||
ui->signMessage->setVisible(true);
|
||||
ui->verifyMessage->setEnabled(false);
|
||||
ui->verifyMessage->setVisible(false);
|
||||
break;
|
||||
}
|
||||
ui->copyToClipboard->setEnabled(true);
|
||||
@@ -243,6 +278,7 @@ void AddressBookPage::selectionChanged()
|
||||
ui->showQRCode->setEnabled(false);
|
||||
ui->copyToClipboard->setEnabled(false);
|
||||
ui->signMessage->setEnabled(false);
|
||||
ui->verifyMessage->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,16 +339,15 @@ void AddressBookPage::on_showQRCode_clicked()
|
||||
QTableView *table = ui->tableView;
|
||||
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
|
||||
|
||||
|
||||
QRCodeDialog *d;
|
||||
foreach (QModelIndex index, indexes)
|
||||
{
|
||||
QString address = index.data().toString(),
|
||||
label = index.sibling(index.row(), 0).data().toString(),
|
||||
title = QString("%1 << %2 >>").arg(label).arg(address);
|
||||
QString address = index.data().toString(), label = index.sibling(index.row(), 0).data(Qt::EditRole).toString();
|
||||
|
||||
QRCodeDialog *d = new QRCodeDialog(title, address, label, tab == ReceivingTab, this);
|
||||
d->show();
|
||||
QRCodeDialog *dialog = new QRCodeDialog(address, label, tab == ReceivingTab, this);
|
||||
if(optionsModel)
|
||||
dialog->setModel(optionsModel);
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->show();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -325,3 +360,15 @@ void AddressBookPage::contextualMenu(const QPoint &point)
|
||||
contextMenu->exec(QCursor::pos());
|
||||
}
|
||||
}
|
||||
|
||||
void AddressBookPage::selectNewAddress(const QModelIndex &parent, int begin, int end)
|
||||
{
|
||||
QModelIndex idx = proxyModel->mapFromSource(model->index(begin, AddressTableModel::Address, parent));
|
||||
if(idx.isValid() && (idx.data(Qt::EditRole).toString() == newAddressToSelect))
|
||||
{
|
||||
// Select row of newly created address, once
|
||||
ui->tableView->setFocus();
|
||||
ui->tableView->selectRow(idx.row());
|
||||
newAddressToSelect.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ namespace Ui {
|
||||
class AddressBookPage;
|
||||
}
|
||||
class AddressTableModel;
|
||||
class OptionsModel;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTableView;
|
||||
class QItemSelection;
|
||||
class QSortFilterProxyModel;
|
||||
class QMenu;
|
||||
class QModelIndex;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
/** Widget that shows a list of sending or receiving addresses.
|
||||
@@ -36,6 +38,7 @@ public:
|
||||
~AddressBookPage();
|
||||
|
||||
void setModel(AddressTableModel *model);
|
||||
void setOptionsModel(OptionsModel *optionsModel);
|
||||
const QString &getReturnValue() const { return returnValue; }
|
||||
|
||||
public slots:
|
||||
@@ -45,12 +48,14 @@ public slots:
|
||||
private:
|
||||
Ui::AddressBookPage *ui;
|
||||
AddressTableModel *model;
|
||||
OptionsModel *optionsModel;
|
||||
Mode mode;
|
||||
Tabs tab;
|
||||
QString returnValue;
|
||||
QSortFilterProxyModel *proxyModel;
|
||||
QMenu *contextMenu;
|
||||
QAction *deleteAction;
|
||||
QString newAddressToSelect;
|
||||
|
||||
private slots:
|
||||
void on_deleteButton_clicked();
|
||||
@@ -58,6 +63,7 @@ private slots:
|
||||
/** Copy address of currently selected address entry to clipboard */
|
||||
void on_copyToClipboard_clicked();
|
||||
void on_signMessage_clicked();
|
||||
void on_verifyMessage_clicked();
|
||||
void selectionChanged();
|
||||
void on_showQRCode_clicked();
|
||||
/** Spawn contextual menu (right mouse menu) for address book entry */
|
||||
@@ -67,6 +73,13 @@ private slots:
|
||||
void onCopyLabelAction();
|
||||
/** Edit currently selected address entry */
|
||||
void onEditAction();
|
||||
|
||||
/** New entry/entries were added to address table */
|
||||
void selectNewAddress(const QModelIndex &parent, int begin, int end);
|
||||
|
||||
signals:
|
||||
void signMessage(QString addr);
|
||||
void verifyMessage(QString addr);
|
||||
};
|
||||
|
||||
#endif // ADDRESSBOOKDIALOG_H
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#include "guiutil.h"
|
||||
#include "walletmodel.h"
|
||||
|
||||
#include "headers.h"
|
||||
#include "wallet.h"
|
||||
#include "base58.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QColor>
|
||||
@@ -26,26 +27,43 @@ struct AddressTableEntry
|
||||
type(type), label(label), address(address) {}
|
||||
};
|
||||
|
||||
// Private implementation
|
||||
struct AddressTablePriv
|
||||
struct AddressTableEntryLessThan
|
||||
{
|
||||
bool operator()(const AddressTableEntry &a, const AddressTableEntry &b) const
|
||||
{
|
||||
return a.address < b.address;
|
||||
}
|
||||
bool operator()(const AddressTableEntry &a, const QString &b) const
|
||||
{
|
||||
return a.address < b;
|
||||
}
|
||||
bool operator()(const QString &a, const AddressTableEntry &b) const
|
||||
{
|
||||
return a < b.address;
|
||||
}
|
||||
};
|
||||
|
||||
// Private implementation
|
||||
class AddressTablePriv
|
||||
{
|
||||
public:
|
||||
CWallet *wallet;
|
||||
QList<AddressTableEntry> cachedAddressTable;
|
||||
AddressTableModel *parent;
|
||||
|
||||
AddressTablePriv(CWallet *wallet):
|
||||
wallet(wallet) {}
|
||||
AddressTablePriv(CWallet *wallet, AddressTableModel *parent):
|
||||
wallet(wallet), parent(parent) {}
|
||||
|
||||
void refreshAddressTable()
|
||||
{
|
||||
cachedAddressTable.clear();
|
||||
|
||||
CRITICAL_BLOCK(wallet->cs_wallet)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, std::string)& item, wallet->mapAddressBook)
|
||||
LOCK(wallet->cs_wallet);
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, std::string)& item, wallet->mapAddressBook)
|
||||
{
|
||||
const CBitcoinAddress& address = item.first;
|
||||
const std::string& strName = item.second;
|
||||
bool fMine = wallet->HaveKey(address);
|
||||
bool fMine = IsMine(*wallet, address.Get());
|
||||
cachedAddressTable.append(AddressTableEntry(fMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending,
|
||||
QString::fromStdString(strName),
|
||||
QString::fromStdString(address.ToString())));
|
||||
@@ -53,6 +71,53 @@ struct AddressTablePriv
|
||||
}
|
||||
}
|
||||
|
||||
void updateEntry(const QString &address, const QString &label, bool isMine, int status)
|
||||
{
|
||||
// Find address / label in model
|
||||
QList<AddressTableEntry>::iterator lower = qLowerBound(
|
||||
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
|
||||
QList<AddressTableEntry>::iterator upper = qUpperBound(
|
||||
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
|
||||
int lowerIndex = (lower - cachedAddressTable.begin());
|
||||
int upperIndex = (upper - cachedAddressTable.begin());
|
||||
bool inModel = (lower != upper);
|
||||
AddressTableEntry::Type newEntryType = isMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending;
|
||||
|
||||
switch(status)
|
||||
{
|
||||
case CT_NEW:
|
||||
if(inModel)
|
||||
{
|
||||
OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_NOW, but entry is already in model\n");
|
||||
break;
|
||||
}
|
||||
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
|
||||
cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address));
|
||||
parent->endInsertRows();
|
||||
break;
|
||||
case CT_UPDATED:
|
||||
if(!inModel)
|
||||
{
|
||||
OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_UPDATED, but entry is not in model\n");
|
||||
break;
|
||||
}
|
||||
lower->type = newEntryType;
|
||||
lower->label = label;
|
||||
parent->emitDataChanged(lowerIndex);
|
||||
break;
|
||||
case CT_DELETED:
|
||||
if(!inModel)
|
||||
{
|
||||
OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_DELETED, but entry is not in model\n");
|
||||
break;
|
||||
}
|
||||
parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
|
||||
cachedAddressTable.erase(lower, upper);
|
||||
parent->endRemoveRows();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int size()
|
||||
{
|
||||
return cachedAddressTable.size();
|
||||
@@ -75,7 +140,7 @@ AddressTableModel::AddressTableModel(CWallet *wallet, WalletModel *parent) :
|
||||
QAbstractTableModel(parent),walletModel(parent),wallet(wallet),priv(0)
|
||||
{
|
||||
columns << tr("Label") << tr("Address");
|
||||
priv = new AddressTablePriv(wallet);
|
||||
priv = new AddressTablePriv(wallet, this);
|
||||
priv->refreshAddressTable();
|
||||
}
|
||||
|
||||
@@ -156,7 +221,7 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
|
||||
switch(index.column())
|
||||
{
|
||||
case Label:
|
||||
wallet->SetAddressBookName(rec->address.toStdString(), value.toString().toStdString());
|
||||
wallet->SetAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString());
|
||||
rec->label = value.toString();
|
||||
break;
|
||||
case Address:
|
||||
@@ -169,19 +234,16 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
|
||||
// Double-check that we're not overwriting a receiving address
|
||||
if(rec->type == AddressTableEntry::Sending)
|
||||
{
|
||||
CRITICAL_BLOCK(wallet->cs_wallet)
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
// Remove old entry
|
||||
wallet->DelAddressBookName(rec->address.toStdString());
|
||||
wallet->DelAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get());
|
||||
// Add new entry with new address
|
||||
wallet->SetAddressBookName(value.toString().toStdString(), rec->label.toStdString());
|
||||
wallet->SetAddressBookName(CBitcoinAddress(value.toString().toStdString()).Get(), rec->label.toStdString());
|
||||
}
|
||||
|
||||
rec->address = value.toString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
emit dataChanged(index, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -231,12 +293,10 @@ QModelIndex AddressTableModel::index(int row, int column, const QModelIndex & pa
|
||||
}
|
||||
}
|
||||
|
||||
void AddressTableModel::updateList()
|
||||
void AddressTableModel::updateEntry(const QString &address, const QString &label, bool isMine, int status)
|
||||
{
|
||||
// Update address book model from Bitcoin core
|
||||
beginResetModel();
|
||||
priv->refreshAddressTable();
|
||||
endResetModel();
|
||||
priv->updateEntry(address, label, isMine, status);
|
||||
}
|
||||
|
||||
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address)
|
||||
@@ -254,9 +314,9 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
|
||||
return QString();
|
||||
}
|
||||
// Check for duplicate addresses
|
||||
CRITICAL_BLOCK(wallet->cs_wallet)
|
||||
{
|
||||
if(wallet->mapAddressBook.count(strAddress))
|
||||
LOCK(wallet->cs_wallet);
|
||||
if(wallet->mapAddressBook.count(CBitcoinAddress(strAddress).Get()))
|
||||
{
|
||||
editStatus = DUPLICATE_ADDRESS;
|
||||
return QString();
|
||||
@@ -273,22 +333,23 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
|
||||
editStatus = WALLET_UNLOCK_FAILURE;
|
||||
return QString();
|
||||
}
|
||||
std::vector<unsigned char> newKey;
|
||||
CPubKey newKey;
|
||||
if(!wallet->GetKeyFromPool(newKey, true))
|
||||
{
|
||||
editStatus = KEY_GENERATION_FAILURE;
|
||||
return QString();
|
||||
}
|
||||
strAddress = CBitcoinAddress(newKey).ToString();
|
||||
strAddress = CBitcoinAddress(newKey.GetID()).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
// Add entry and update list
|
||||
CRITICAL_BLOCK(wallet->cs_wallet)
|
||||
wallet->SetAddressBookName(strAddress, strLabel);
|
||||
updateList();
|
||||
// Add entry
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
wallet->SetAddressBookName(CBitcoinAddress(strAddress).Get(), strLabel);
|
||||
}
|
||||
return QString::fromStdString(strAddress);
|
||||
}
|
||||
|
||||
@@ -302,27 +363,21 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren
|
||||
// Also refuse to remove receiving addresses.
|
||||
return false;
|
||||
}
|
||||
CRITICAL_BLOCK(wallet->cs_wallet)
|
||||
{
|
||||
wallet->DelAddressBookName(rec->address.toStdString());
|
||||
LOCK(wallet->cs_wallet);
|
||||
wallet->DelAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get());
|
||||
}
|
||||
updateList();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AddressTableModel::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* Look up label for address in address book, if not found return empty string.
|
||||
*/
|
||||
QString AddressTableModel::labelForAddress(const QString &address) const
|
||||
{
|
||||
CRITICAL_BLOCK(wallet->cs_wallet)
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
CBitcoinAddress address_parsed(address.toStdString());
|
||||
std::map<CBitcoinAddress, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed);
|
||||
std::map<CTxDestination, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed.Get());
|
||||
if (mi != wallet->mapAddressBook.end())
|
||||
{
|
||||
return QString::fromStdString(mi->second);
|
||||
@@ -345,3 +400,7 @@ int AddressTableModel::lookupAddress(const QString &address) const
|
||||
}
|
||||
}
|
||||
|
||||
void AddressTableModel::emitDataChanged(int idx)
|
||||
{
|
||||
emit dataChanged(index(idx, 0, QModelIndex()), index(idx, columns.length()-1, QModelIndex()));
|
||||
}
|
||||
|
||||
@@ -56,10 +56,6 @@ public:
|
||||
*/
|
||||
QString addRow(const QString &type, const QString &label, const QString &address);
|
||||
|
||||
/* Update address list from core. Invalidates any indices.
|
||||
*/
|
||||
void updateList();
|
||||
|
||||
/* Look up label for address in address book, if not found return empty string.
|
||||
*/
|
||||
QString labelForAddress(const QString &address) const;
|
||||
@@ -78,11 +74,18 @@ private:
|
||||
QStringList columns;
|
||||
EditStatus editStatus;
|
||||
|
||||
/** Notify listeners that data changed. */
|
||||
void emitDataChanged(int index);
|
||||
|
||||
signals:
|
||||
void defaultAddressChanged(const QString &address);
|
||||
|
||||
public slots:
|
||||
void update();
|
||||
/* Update address list from core.
|
||||
*/
|
||||
void updateEntry(const QString &address, const QString &label, bool isMine, int status);
|
||||
|
||||
friend class AddressTablePriv;
|
||||
};
|
||||
|
||||
#endif // ADDRESSTABLEMODEL_H
|
||||
|
||||
@@ -24,7 +24,6 @@ AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
|
||||
ui->passEdit1->installEventFilter(this);
|
||||
ui->passEdit2->installEventFilter(this);
|
||||
ui->passEdit3->installEventFilter(this);
|
||||
ui->capsLabel->clear();
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
@@ -99,7 +98,7 @@ void AskPassphraseDialog::accept()
|
||||
break;
|
||||
}
|
||||
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm wallet encryption"),
|
||||
tr("WARNING: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!\nAre you sure you wish to encrypt your wallet?"),
|
||||
tr("Warning: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!") + "<br><br>" + tr("Are you sure you wish to encrypt your wallet?"),
|
||||
QMessageBox::Yes|QMessageBox::Cancel,
|
||||
QMessageBox::Cancel);
|
||||
if(retval == QMessageBox::Yes)
|
||||
@@ -109,7 +108,16 @@ void AskPassphraseDialog::accept()
|
||||
if(model->setWalletEncrypted(true, newpass1))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Wallet encrypted"),
|
||||
tr("Bitcoin will close now to finish the encryption process. Remember that encrypting your wallet cannot fully protect your bitcoins from being stolen by malware infecting your computer."));
|
||||
"<qt>" +
|
||||
tr("Bitcoin will close now to finish the encryption process. "
|
||||
"Remember that encrypting your wallet cannot fully protect "
|
||||
"your bitcoins from being stolen by malware infecting your computer.") +
|
||||
"<br><br><b>" +
|
||||
tr("IMPORTANT: Any previous backups you have made of your wallet file "
|
||||
"should be replaced with the newly generated, encrypted wallet file. "
|
||||
"For security reasons, previous backups of the unencrypted wallet file "
|
||||
"will become useless as soon as you start using the new, encrypted wallet.") +
|
||||
"</b></qt>");
|
||||
QApplication::quit();
|
||||
}
|
||||
else
|
||||
@@ -158,7 +166,7 @@ void AskPassphraseDialog::accept()
|
||||
if(model->changePassphrase(oldpass, newpass1))
|
||||
{
|
||||
QMessageBox::information(this, tr("Wallet encrypted"),
|
||||
tr("Wallet passphrase was succesfully changed."));
|
||||
tr("Wallet passphrase was successfully changed."));
|
||||
QDialog::accept(); // Success
|
||||
}
|
||||
else
|
||||
@@ -178,7 +186,7 @@ void AskPassphraseDialog::accept()
|
||||
|
||||
void AskPassphraseDialog::textChanged()
|
||||
{
|
||||
// Validate input, set Ok button to enabled when accepable
|
||||
// Validate input, set Ok button to enabled when acceptable
|
||||
bool acceptable = false;
|
||||
switch(mode)
|
||||
{
|
||||
@@ -205,7 +213,7 @@ bool AskPassphraseDialog::event(QEvent *event)
|
||||
fCapsLock = !fCapsLock;
|
||||
}
|
||||
if (fCapsLock) {
|
||||
ui->capsLabel->setText(tr("Warning: The Caps Lock key is on."));
|
||||
ui->capsLabel->setText(tr("Warning: The Caps Lock key is on!"));
|
||||
} else {
|
||||
ui->capsLabel->clear();
|
||||
}
|
||||
@@ -215,7 +223,7 @@ bool AskPassphraseDialog::event(QEvent *event)
|
||||
|
||||
bool AskPassphraseDialog::eventFilter(QObject *, QEvent *event)
|
||||
{
|
||||
/* Detect Caps Lock.
|
||||
/* Detect Caps Lock.
|
||||
* There is no good OS-independent way to check a key state in Qt, but we
|
||||
* can detect Caps Lock by checking for the following condition:
|
||||
* Shift key is down and the result is a lower case character, or
|
||||
@@ -229,7 +237,7 @@ bool AskPassphraseDialog::eventFilter(QObject *, QEvent *event)
|
||||
bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
|
||||
if ((fShift && psz->isLower()) || (!fShift && psz->isUpper())) {
|
||||
fCapsLock = true;
|
||||
ui->capsLabel->setText(tr("Warning: The Caps Lock key is on."));
|
||||
ui->capsLabel->setText(tr("Warning: The Caps Lock key is on!"));
|
||||
} else if (psz->isLetter()) {
|
||||
fCapsLock = false;
|
||||
ui->capsLabel->clear();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user