Skip to content

Commit 99af958

Browse files
Jeff GarzikJeff Garzik
authored andcommitted
Add MIT/X11 license, configuration file and new-block event modularization
1 parent f676246 commit 99af958

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

COPYING

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
Permission is hereby granted, free of charge, to any person obtaining a copy
3+
of this software and associated documentation files (the "Software"), to deal
4+
in the Software without restriction, including without limitation the rights
5+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6+
copies of the Software, and to permit persons to whom the Software is
7+
furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in
10+
all copies or substantial portions of the Software.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
THE SOFTWARE.
19+

node.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
#!/usr/bin/python
2+
#
3+
# node.py - Bitcoin P2P network half-a-node
4+
#
5+
# Distributed under the MIT/X11 software license, see the accompanying
6+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
7+
#
28

39
import struct
410
import socket
511
import asyncore
612
import binascii
713
import time
814
import sys
15+
import re
916
import random
1017
import cStringIO
1118
from Crypto.Hash import SHA256
1219

1320
MY_VERSION = 312
1421
MY_SUBVERSION = ".4"
1522

23+
settings = {}
24+
25+
def new_block_event():
26+
print "New block noticed"
27+
1628
def deser_string(f):
1729
nit = struct.unpack("<B", f.read(1))[0]
1830
if nit == 253:
@@ -632,7 +644,28 @@ def got_message(self, message):
632644
if not message.block.is_valid():
633645
print "invalid block"
634646
else:
635-
print "WOOOOOO!!!!! We have a block!"
647+
new_block_event()
648+
649+
if __name__ == '__main__':
650+
if len(sys.argv) != 2:
651+
print "Usage: node.py CONFIG-FILE"
652+
sys.exit(1)
653+
654+
f = open(sys.argv[1])
655+
for line in f:
656+
m = re.search('^(\w+)\s*=\s*(\S.*)$', line)
657+
if m is None:
658+
continue
659+
settings[m.group(1)] = m.group(2)
660+
f.close()
661+
662+
if 'host' not in settings:
663+
settings['host'] = '127.0.0.1'
664+
if 'port' not in settings:
665+
settings['port'] = 8333
666+
667+
settings['port'] = int(settings['port'])
668+
669+
c = NodeConn(settings['host'], settings['port'])
670+
asyncore.loop()
636671

637-
c = NodeConn("127.0.0.1", 8333)
638-
asyncore.loop()

0 commit comments

Comments
 (0)