built alias/nickname feature for nodes, in the process I broke the message color system.. can be fixed in main.js line 170
This commit is contained in:
parent
5e0fd9c935
commit
d6f081f8b0
24
main.py
24
main.py
@ -31,6 +31,7 @@ class Meshenger:
|
||||
logger.info('Making message directory')
|
||||
|
||||
self.init_index()
|
||||
self.make_alias()
|
||||
|
||||
try:
|
||||
d = threading.Thread(target=self.discover)
|
||||
@ -179,9 +180,9 @@ Initialize the index. Read from disk or create new.
|
||||
|
||||
def build_index(self):
|
||||
"""
|
||||
Make an index file of all the messages present on the node.
|
||||
Save the time of the last update.
|
||||
"""
|
||||
Make an index file of all the messages present on the node.
|
||||
Save the time of the last update.
|
||||
"""
|
||||
logger.debug('build_index')
|
||||
current_index = os.listdir(self.msg_dir)
|
||||
if current_index != self.previous_index:
|
||||
@ -198,11 +199,24 @@ Save the time of the last update.
|
||||
|
||||
self.previous_index = current_index
|
||||
|
||||
def make_alias(self):
|
||||
"""
|
||||
See if the node already has an alias (nickname) if not just use the IP-Hash
|
||||
"""
|
||||
if not os.path.exists('alias'):
|
||||
with open('alias','wb') as alias:
|
||||
self.alias = self.own_hash
|
||||
alias.write(self.own_hash)
|
||||
else:
|
||||
self.alias = open('alias','rb').read().replace('\n','') #should we replace the newline?
|
||||
pass
|
||||
logger.debug('Alias is "'+self.alias+'"')
|
||||
|
||||
|
||||
def get_index(self,ip, path):
|
||||
"""
|
||||
Download the indices from other nodes.
|
||||
"""
|
||||
Download the indices from other nodes.
|
||||
"""
|
||||
|
||||
os.system('wget http://['+ip+'%adhoc0]:'+self.serve_port+'/index -O '+os.path.join(path,'index'))
|
||||
|
||||
|
@ -32,6 +32,15 @@ Serve index and messages
|
||||
self.wfile.write(meshenger.own_hash)
|
||||
else:
|
||||
self.send_error(404,'Id not yet available')
|
||||
elif self.path == '/alias':
|
||||
if meshenger and meshenger.alias:
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text-html')
|
||||
self.end_headers()
|
||||
self.wfile.write(meshenger.alias)
|
||||
else:
|
||||
self.send_error(404,'Alias not yet available')
|
||||
|
||||
elif self.path == '/log':
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text-html')
|
||||
|
@ -38,6 +38,10 @@ Serve index and messages
|
||||
if self.path == '/index' or self.path.startswith( self.messageDir ):
|
||||
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
|
||||
|
||||
if self.path == '/alias' or self.path.startswith( self.messageDir ):
|
||||
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
|
||||
|
||||
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
|
20
web/main.js
20
web/main.js
@ -2,7 +2,7 @@ localStorage.clear();
|
||||
|
||||
|
||||
//These need to be obtained from the node
|
||||
var ownId, ownColor;
|
||||
var ownId, ownColor, ownAlias;
|
||||
|
||||
/*
|
||||
* OUTBOX STUFF
|
||||
@ -19,11 +19,12 @@ document.getElementById('message-form').onsubmit = function(){
|
||||
var mess = document.getElementById('message').value.replace(/\r?\n/g, "<br />");
|
||||
var newMsgs = {};
|
||||
var ddata = new Date().getTime();
|
||||
var alias = ownAlias //to do: build a check to see if ownAlias == ownId, if so, alias should become 'local'
|
||||
var contento = {
|
||||
"time" : ddata,
|
||||
"message" : mess,
|
||||
"name" : namm,
|
||||
"node" : "local",
|
||||
"node" : alias,
|
||||
"hops" : "0"
|
||||
}
|
||||
newMsgs.message = contento;
|
||||
@ -233,6 +234,7 @@ function downloadMessage(filename) {
|
||||
xhr.open( "GET", 'msg/'+filename, true);
|
||||
xhr.send();
|
||||
|
||||
|
||||
}
|
||||
function checkInbox() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
@ -256,6 +258,17 @@ function getOwnId() {
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function getOwnAlias() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function(){
|
||||
if (xhr.readyState == 4 && xhr.status == 200){
|
||||
ownAlias = xhr.responseText;
|
||||
}
|
||||
}
|
||||
xhr.open( "GET", 'alias', true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* INIT
|
||||
@ -265,6 +278,9 @@ function update(){
|
||||
if ( !ownId ){
|
||||
getOwnId();
|
||||
}
|
||||
if ( !ownAlias){
|
||||
getOwnAlias();
|
||||
}
|
||||
checkInbox();
|
||||
// also check for outbox items on interval,
|
||||
// necessary in case connection is lost and messages are not yet sent
|
||||
|
Loading…
Reference in New Issue
Block a user