This commit is contained in:
Oskar Thoren 2019-02-06 05:21:48 -05:00
parent c32d95cc4b
commit bfe68e53f6
4 changed files with 91 additions and 13 deletions

View File

@ -26,3 +26,13 @@ geth --testnet --rpc --maxpeers=25 --shh --shh.pow=0.002 --rpcport=8501 --datadi
- add nodes to connect
- running whisper node on own nodes?
cp static-nodes.json ~/.ethereum/testnet/geth/
# send 1:1 chat
0x04cfc3a0f6c1cb824823164603959c639f99680485da2446dc316969faca00421b20dba3996bf99b8b5db7745eace60545a77e54784e91e440aa1af931161de3a6
geth --testnet --rpc --maxpeers=25 --shh --shh.pow=0.002 --rpcport=8501 --datadir=/tmp/bar --port=30001 --ipcpath /tmp/bar.ipc
geth --testnet --rpc --maxpeers=25 --shh --shh.pow=0.002 --rpcport=8501 --datadir=~/.ethereum/node-b --port=30001

View File

@ -0,0 +1,14 @@
[
"enode://436cc6f674928fdc9a9f7990f2944002b685d1c37f025c1be425185b5b1f0900feaf1ccc2a6130268f9901be4a7d252f37302c8335a2c1a62736e9232691cc3a@174.138.105.243:30404",
"enode://5395aab7833f1ecb671b59bf0521cf20224fe8162fc3d2675de4ee4d5636a75ec32d13268fc184df8d1ddfa803943906882da62a4df42d4fccf6d17808156a87@206.189.243.57:30404",
"enode://7427dfe38bd4cf7c58bb96417806fab25782ec3e6046a8053370022cbaa281536e8d64ecd1b02e1f8f72768e295d06258ba43d88304db068e6f2417ae8bcb9a6@104.154.88.123:30404",
"enode://ebefab39b69bbbe64d8cd86be765b3be356d8c4b24660f65d493143a0c44f38c85a257300178f7845592a1b0332811542e9a58281c835babdd7535babb64efc1@35.202.99.224:30404",
"enode://a6a2a9b3a7cbb0a15da74301537ebba549c990e3325ae78e1272a19a3ace150d03c184b8ac86cc33f1f2f63691e467d49308f02d613277754c4dccd6773b95e8@206.189.243.176:30304",
"enode://207e53d9bf66be7441e3daba36f53bfbda0b6099dba9a865afc6260a2d253fb8a56a72a48598a4f7ba271792c2e4a8e1a43aaef7f34857f520c8c820f63b44c8@35.224.15.65:30304",
"enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@206.189.243.162:30504",
"enode://7aa648d6e855950b2e3d3bf220c496e0cae4adfddef3e1e6062e6b177aec93bc6cdcf1282cb40d1656932ebfdd565729da440368d7c4da7dbd4d004b1ac02bf8@206.189.243.169:30504",
"enode://8a64b3c349a2e0ef4a32ea49609ed6eb3364be1110253c20adc17a3cebbc39a219e5d3e13b151c0eee5d8e0f9a8ba2cd026014e67b41a4ab7d1d5dd67ca27427@206.189.243.168:30504",
"enode://7de99e4cb1b3523bd26ca212369540646607c721ad4f3e5c821ed9148150ce6ce2e72631723002210fac1fd52dfa8bbdf3555e05379af79515e1179da37cc3db@35.188.19.210:30504",
"enode://015e22f6cd2b44c8a51bd7a23555e271e0759c7d7f52432719665a74966f2da456d28e154e836bee6092b4d686fe67e331655586c57b718be3997c1629d24167@35.226.21.19:30504",
"enode://531e252ec966b7e83f5538c19bf1cde7381cc7949026a6e499b6e998e695751aadf26d4c98d5a4eabfb7cefd31c3c88d600a775f14ed5781520a88ecd25da3c6@35.225.227.79:30504"
]

1
data_sync/test.json Normal file
View File

@ -0,0 +1 @@
["~#c4",["Hello","text/plain","~:user-message",154938955408101,1549389554080,["^ ","~:chat-id","0x04d94a1a01872b598c7 cdc5aca2358d35eb91cd8a91eaea8da277451bb71d45c0d1eb87a31ea04e32f537e90165c870b3e115a12438c754d507ac75bddd6ecacd5","~:text","Hello"]]]

View File

@ -15,7 +15,9 @@ b_keyPair= "0x7b5c5af9736d9f1773f2020dd0fef0bc3c8aeaf147d2bf41961e766588e086e7"
a_pubKey = "0x04d94a1a01872b598c7cdc5aca2358d35eb91cd8a91eaea8da277451bb71d45c0d1eb87a31ea04e32f537e90165c870b3e115a12438c754d507ac75bddd6ecacd5"
b_pubKey = "0x04ff921ddf78b5ed4537402f59a150caf9d96a83f2a345a1ddf9df12e99e7778f314c9ca72e8285eb213af84f5a7b01aabb62c67e46657976ded6658e1b9e83c73"
topic = '0x00000000'
#(def discovery-topic "0xf8946aac")
topic="0xf8946aac"
#topic = '0x00000000'
# API
#---------------------------------------------------------------------
@ -35,7 +37,7 @@ def pollFilter(topic, keyPair):
return myFilter
def sendMessage(address_to, topic, msg):
print("address_to", address_to)
#print("address_to", address_to)
web3.shh.post({
'pubKey': address_to,
'topic': topic,
@ -50,8 +52,9 @@ def getMessages(myFilter):
retreived_messages = web3.shh.getMessages(filterID)
for i in range(0, len(retreived_messages)):
print(retreived_messages[i]['payload'].decode("utf-8"))
print(retreived_messages[i])
#print(retreived_messages[i]['payload'])
print("\nRECV " + retreived_messages[i]['payload'].decode("utf-8"))
#print(retreived_messages[i])
# Run
#---------------------------------------------------------------------
@ -62,9 +65,9 @@ class Daemon:
def run(self):
while True:
sendMessage(address_to, topic, "hello")
#sendMessage(address_to, topic, "hello")
getMessages(myFilter)
print("tick")
#print("tick")
time.sleep(0.3)
# Args
@ -76,17 +79,24 @@ if len(sys.argv) < 2:
node = sys.argv[1]
# what
oskar="0x04d94a1a01872b598c7cdc5aca2358d35eb91cd8a91eaea8da277451bb71d45c0d1eb87a31ea04e32f537e90165c870b3e115a12438c754d507ac75bddd6ecacd5"
# contact code
#oskar="0x04cfc3a0f6c1cb824823164603959c639f99680485da2446dc316969faca00421b20dba3996bf99b8b5db7745eace60545a77e54784e91e440aa1af931161de3a6"
if(node == "a"):
print("a")
keyPair = a_keyPair
# XXX: Seems weird, should be b_pubkey?
address_to = a_pubKey
address_to = oskar
#address_to = a_pubKey # Works
#address_to = b_pubKey
host = "http://localhost:8500"
elif(node == "b"):
print("b")
keyPair = b_keyPair
address_to = a_pubKey
address_to = oskar
#address_to = a_pubKey
host = "http://localhost:8501"
else:
print("Unknown node")
@ -122,13 +132,49 @@ sendMessage(address_to, topic, "hi also")
#myFilter = pollFilter(topic, a_keyPair)
#sendMessage(b_pubKey, topic, "hello b")
#sendMessage(a_pubKey, topic, "hello a")
#getMessages(myFilter)
getMessages(myFilter)
#lol="\[\"~#c4\",\[\"Helloaa\",\"text/plain\",\"~:user-message\",154938955408101,1549389554080,\[\"^ \",\"~:chat-id\",\"0x04d94a1a01872b598c7cdc5aca2358d35eb91cd8a91eaea8da277451bb71d45c0d1eb87a31ea04e32f537e90165c870b3e115a12438c754d507ac75bddd6ecacd5\",\"~:text\",\"Hellbaro\"]]]"
#raw = b'["~#c4",["Test","text/plain","~:user-message",154939130505401,1549391305053,["^ ","~:chat-id","0x04d94a1a01872b598c7cdc5aca2358d35eb91cd8a91eaea8da277451bb71d45c0d1eb87a31ea04e32f537e90165c870b3e115a12438c754d507ac75bddd6ecacd5","~:text","Test"]]]'
#raw = b'["~#c4",["Test2","text/plain","~:user-message",154939130605401,1549391306053,["^ ","~:chat-id","0x04d94a1a01872b598c7cdc5aca2358d35eb91cd8a91eaea8da277451bb71d45c0d1eb87a31ea04e32f537e90165c870b3e115a12438c754d507ac75bddd6ecacd5","~:text","Test2"]]]'
#json = ['~#c4', ['Test', 'text/plain', '~:user-message', 154939130505401, 1549391305053, ['^ ', '~:chat-id', '0x04d94a1a01872b598c7cdc5aca2358d35eb91cd8a91eaea8da277451bb71d45c0d1eb87a31ea04e32f537e90165c870b3e115a12438c754d507ac75bddd6ecacd5', '~:text', 'Test']]]
#import json
#json_str = json.loads(raw.decode('utf-8'))
#print(json_str)
def run():
while True:
# lol
time.sleep(0.5)
text = input("> ")
#sendMessage(oskar, topic, lol)
#test = raw.decode('utf-8')
print("SEND " + text)
# Sending to A over discovery topic
# something wrong here
sendMessage(a_pubKey, topic, text)
#sendMessage(oskar, topic, test)
#sendMessage(a_pubKey, topic, "hello" + text)
#sendMessage(oskar, topic, "hello" + text)
# Take address_to and filter as args?
threads = []
daemon = Thread(target=Daemon().run())
threads.append(daemon)
daemon.start()
#threads = []
#daemon = Thread(target=Daemon().run())
#repl = Thread(target=run())
#threads.append(daemon)
#threads.append(repl)
#daemon.start()
#repl.start()
b = Thread(name='background', target=Daemon().run)
f = Thread(name='foreground', target=run)
b.start()
f.start()
# TODO
# Usage:
@ -143,3 +189,10 @@ daemon.start()
# - try to get end to end e.g. mobile phone
# - hook up to sync
# - consider subscribe instead?
# Connect to nodes
# listen to public channel all channels?
# Can receive messages from mobile, just not send