Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pquerna committed Dec 14, 2010
1 parent 4fcd1ab commit e11b54b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions udp/tftp.js
Expand Up @@ -48,13 +48,13 @@ function decodeOp(msg, peer) {
function clearSession(peer) {
var key = peer.address + ":" + peer.port;
delete sessions[key];
};
}

function startSession(peer, file) {
var key = peer.address + ":" + peer.port;
sessions[key] = {'peer': peer, 'file': file};
sendBlock(peer, file, 1);
};
}

function continueSession(peer, block) {
var key = peer.address + ":" + peer.port;
Expand All @@ -63,9 +63,9 @@ function continueSession(peer, block) {
sendBlock(peer, s.file, block);
}
else {
log(peer, 'Ack for unknown session')
log(peer, 'Ack for unknown session');
}
};
}

var ERR_UNDEFINED = 0; /* Not defined, see error message (if any). */
var ERR_FILE_NOT_FOUND = 1; /* File not found. */
Expand Down Expand Up @@ -131,6 +131,7 @@ function sendBlock(peer, file, block) {
sock = dgram.createSocket("udp4", function (msg, peer) {
var key = peer.address + ":" + peer.port;
var op = decodeOp(msg, peer);
var buf = null;

if (op === null) {
sendError(peer, ERR_UNDEFINED, 'Unable to decode opcode');
Expand All @@ -140,7 +141,7 @@ sock = dgram.createSocket("udp4", function (msg, peer) {
log(peer, 'OP '+ op);
switch (op) {
case "OPCODE_RRQ":
var buf = msg.slice(2);
buf = msg.slice(2);
var tmp = getString(buf);
buf = buf.slice(tmp[0]+1);

Expand All @@ -165,7 +166,7 @@ sock = dgram.createSocket("udp4", function (msg, peer) {
sendError(peer, ERR_ACCESS_VIOLATION, 'Read only tftp server');
break;
case "OPCODE_ACK":
var buf = msg.slice(2);
buf = msg.slice(2);
var block = (parseInt(buf[0]) << 8) +parseInt(buf[1]);
continueSession(peer, block + 1);
break;
Expand Down

0 comments on commit e11b54b

Please sign in to comment.