From: Paul J R Date: Wed, 16 Jan 2013 20:31:48 +0000 (+1100) Subject: removing a module a installed via npm for fun X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=58109845ae41cbdea4483ad2b875808f0347fd0c;p=random_node_code.git removing a module a installed via npm for fun --- diff --git a/tftp/node_modules/.bin/tftp-client b/tftp/node_modules/.bin/tftp-client deleted file mode 120000 index a47905f..0000000 --- a/tftp/node_modules/.bin/tftp-client +++ /dev/null @@ -1 +0,0 @@ -../tftp-client/bin/tftp.js \ No newline at end of file diff --git a/tftp/node_modules/tftp-client/.npmignore b/tftp/node_modules/tftp-client/.npmignore deleted file mode 100644 index 84a3249..0000000 --- a/tftp/node_modules/tftp-client/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -.git* -example/ \ No newline at end of file diff --git a/tftp/node_modules/tftp-client/README.md b/tftp/node_modules/tftp-client/README.md deleted file mode 100644 index ca09b89..0000000 --- a/tftp/node_modules/tftp-client/README.md +++ /dev/null @@ -1,64 +0,0 @@ -# TFTP-Client - -A simple TFTP client for Node.Js. -*Should not be used in production - first of all: this module is at an early stage (written in less than 12 hours), second: tftp is terrible* - -## Install - -### As a module -`npm install tftp-client` - -### As CLI -`npm install -g tftp-client` - -## Usage - -### Module - -`var client = new TFTP(port, client)` to create a new client. - -`client.read(filename, callback)` to **read** from the server. - ~ The Callback is passed 2 arguments `(err, data)`, where `data` is the contents of the file. - -`client.write(filename, data, callback)` to **write** to the server, where `data` is the contents of the file. - ~ The callback is passed 2 arguments `(err, bytes)`, where `bytes` is the number of bytes sent. - -**Simple read example:** - -```javascript -var TFTP = require('tftp-client'); - -// Initialize the tftp client -var client = new TFTP(69, 'localhost'); - -// Read 1.txt from the server -client.read('1.txt', function (err, data) { - if (err) { - console.error('ERROR:'); - console.error(err); - return; - } - - console.log('Got data (%d bytes). First 100 bytes:', data.length); - console.log(data.toString('utf8', 0, 100)); -}); -``` - -### Command line - -To install the tftp-client as CLI, run `npm install -g tftp-client`. - -`tftp-client (read|write) []` -* hostname - Hostname of tftp server -* read|write - Wether you want to read or write -* filename - Path to the file you want to read or write -* port - Optional. Defaults to 69 - -**Example**: -`tftp-client localhost read 1.txt` - -## TODO - -- Error packets - [RFC](http://tools.ietf.org/html/rfc1350#page-8). (implemented, but not tested) -- Do the initial connection as defined in section 4 (TID's: port numbers from request ack) - [RFC](http://tools.ietf.org/html/rfc1350#section-4). -- Currently, any DATA or ACK packet is responded to. Eg. An ACK packet will get a `DATA` response. There is not check for the block numbers to be in order. diff --git a/tftp/node_modules/tftp-client/TFTP-Client.sublime-project b/tftp/node_modules/tftp-client/TFTP-Client.sublime-project deleted file mode 100644 index 02d0d4b..0000000 --- a/tftp/node_modules/tftp-client/TFTP-Client.sublime-project +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folders": - [ - { - "path": "/D/Dokumenter/GitHub/TFTP-Client" - } - ] -} diff --git a/tftp/node_modules/tftp-client/TFTP-Client.sublime-workspace b/tftp/node_modules/tftp-client/TFTP-Client.sublime-workspace deleted file mode 100644 index 35cc7eb..0000000 --- a/tftp/node_modules/tftp-client/TFTP-Client.sublime-workspace +++ /dev/null @@ -1,575 +0,0 @@ -{ - "auto_complete": - { - "selected_items": - [ - [ - "exists", - "path.existsSync(path);" - ], - [ - "cons", - "console.error();" - ], - [ - "D", - "Dokumenter" - ], - [ - "process", - "process.exit(code);" - ], - [ - "proces", - "process.exit(code);" - ], - [ - "createse", - "http.createServer(requestListener);" - ], - [ - "createSe", - "http.createServer(requestListener);" - ], - [ - "child", - "child_process.exec(command /*, options, callback */);" - ], - [ - "timeout", - "timers.setTimeout(callback, after);" - ], - [ - "node", - "node.events.EventEmitter.on Snippet: NodeJS EventEmitter" - ] - ] - }, - "buffers": - [ - { - "file": "package.json", - "settings": - { - "buffer_size": 242, - "line_ending": "Windows", - "name": "package.json" - } - }, - { - "file": "lib/tftp.js", - "settings": - { - "buffer_size": 7942, - "line_ending": "Windows", - "name": "tftp.js" - } - }, - { - "file": "bin/tftp.js", - "settings": - { - "buffer_size": 2683, - "line_ending": "Windows" - } - }, - { - "file": "README.md", - "settings": - { - "buffer_size": 1790, - "line_ending": "Windows", - "name": "README.md" - } - } - ], - "build_system": "", - "command_palette": - { - "height": 380.0, - "selected_items": - [ - [ - "mark", - "Markdown Preview: preview in Browser" - ], - [ - "git diff", - "Git: Diff Current File" - ], - [ - "markd", - "Markdown Preview: preview in Browser" - ], - [ - "markdown", - "Markdown Preview: preview in Browser" - ], - [ - "npm", - "Nodejs::NPM::Command" - ], - [ - "npl", - "Nodejs::NPM::List" - ], - [ - "install", - "Package Control: Install Package" - ], - [ - "MARK", - "Markdown Preview: preview in Browser" - ], - [ - "markdo", - "Markdown Preview: preview in Browser" - ], - [ - "git", - "Git: Gui" - ], - [ - "gitadd", - "Git: Add..." - ], - [ - "remo", - "Package Control: Remove Package" - ], - [ - "gut", - "GitHub: Open Gist in Browser" - ], - [ - "intall", - "Package Control: Install Package" - ], - [ - "snippet", - "Snippet: setTimeout function" - ], - [ - "kar", - "Package Control: Add Repository" - ], - [ - "ma", - "Markdown Preview: preview in Sublime Text" - ], - [ - "list", - "Package Control: List Packages" - ], - [ - "package", - "Package Control: List Packages" - ], - [ - "mar", - "Markdown Preview: preview in Browser" - ], - [ - "Package Control: list", - "Package Control: List Packages" - ], - [ - "insta", - "Package Control: Install Package" - ], - [ - "node", - "Nodejs::Run::Current File" - ], - [ - "package up", - "Package Control: Upgrade Package" - ], - [ - "list packa", - "Package Control: Install Package" - ], - [ - "package install", - "Package Control: Install Package" - ], - [ - "package discover", - "Package Control: Discover Packages" - ] - ], - "width": 512.0 - }, - "console": - { - "height": 227.0 - }, - "distraction_free": - { - "menu_visible": true, - "show_minimap": false, - "show_open_files": false, - "show_tabs": false, - "side_bar_visible": false, - "status_bar_visible": false - }, - "file_history": - [ - "/D/Dokumenter/GitHub/TFTP-Client/TFTP-Client.sublime-project", - "/D/Dokumenter/GitHub/TFTP-Client/.npmignore", - "/D/Dokumenter/GitHub/TFTP-Client/example/read.js", - "/D/Dokumenter/GitHub/TFTP-Client/example/write.js", - "/D/Dokumenter/GitHub/TFTP-Client/bin/tftp.js", - "/C/Users/Kristjan/AppData/Roaming/Sublime Text 2/Packages/Default/Default (Windows).sublime-keymap", - "/D/Dokumenter/GitHub/TFTP-Client/lib/write.js", - "/D/Dokumenter/GitHub/TFTP-Client/lib/read.js", - "/D/Dokumenter/GitHub/TFTP-Client/example/transaction.js", - "/D/Dokumenter/GitHub/JsControl/JsControl.sublime-project", - "/D/Dokumenter/GitHub/JsControl/test.js", - "/D/Dokumenter/GitHub/JsControl/.gitignore", - "/D/Dokumenter/GitHub/JsControl/JsControl.js", - "/D/Dokumenter/GitHub/JsControl/controller/test.js", - "/D/Dokumenter/GitHub/JsControl/package.json", - "/D/Dokumenter/GitHub/JsControl/plugins/playerlist/player.js", - "/D/Dokumenter/GitHub/JsControl/controller/modules/maps.js", - "/D/Dokumenter/GitHub/JsControl/controller/modules/game.js", - "/D/Dokumenter/GitHub/JsControl/config/config.json", - "/D/Dokumenter/GitHub/JsControl/Run.cmd", - "/D/Dokumenter/GitHub/JsControl/plugins/playerlist/index.js", - "/D/Dokumenter/GitHub/JsControl/config/players.sample.json", - "/D/Dokumenter/GitHub/JsControl/README.md", - "/D/Dokumenter/GitHub/JsControl/controller/modules/players/players.js", - "/D/Dokumenter/GitHub/JsControl/config/config.sample.json", - "/D/Dokumenter/GitHub/JsControl/todo.md", - "/D/Dokumenter/GitHub/JsControl/Plugins/second/index.js", - "/D/Dokumenter/GitHub/JsControl/controller/player.js", - "/D/Dokumenter/GitHub/JsControl/config/plugins/admin.sample.json", - "/D/Dokumenter/GitHub/JsControl/controller/players.js", - "/D/Dokumenter/GitHub/JsControl/Plugins/admin.js", - "/D/Dokumenter/GitHub/JsControl/plugins/commands.js", - "/D/Dokumenter/GitHub/JsControl/plugins/database.js", - "/C/Users/Kristjan/AppData/Roaming/Sublime Text 2/Packages/User/Distraction Free.sublime-settings", - "/C/Users/Kristjan/AppData/Roaming/Sublime Text 2/Packages/User/Default (Windows).sublime-keymap", - "/D/Dokumenter/GitHub/JsControl/Plugins/webcontroller/index.js", - "/D/Dokumenter/GitHub/JsControl/config/plugins/webcontroller.json", - "/D/Dokumenter/GitHub/JsControl/config/config.js", - "/D/Dokumenter/GitHub/JsControl/config/plugins/webcontroller.js", - "/D/Dokumenter/GitHub/node-gbxremote/package.json", - "/D/Dokumenter/GitHub/node-gbxremote/lib/gbxremote.js", - "/D/Dokumenter/GitHub/node-gbxremote/lib/client.js", - "/D/Dokumenter/GitHub/node-gbxremote/.gitignore", - "/D/Dokumenter/GitHub/node-gbxremote/example/client.js", - "/D/Dokumenter/GitHub/node-gbxremote/lib/deserializer.js", - "/D/Dokumenter/GitHub/node-gbxremote/example/authenticate.js", - "/C/Users/Kristjan/AppData/Roaming/Sublime Text 2/Packages/Default/Preferences.sublime-settings", - "/C/Users/Kristjan/AppData/Roaming/Sublime Text 2/Packages/User/Preferences.sublime-settings" - ], - "find": - { - "height": 34.0 - }, - "find_in_files": - { - "height": 0.0, - "where_history": - [ - "todo.md", - "controller.js", - "" - ] - }, - "find_state": - { - "case_sensitive": false, - "find_history": - [ - "Timeout", - "- ", - "tftp is terrible", - "argc", - "length", - "args", - "line", - "bytes", - "createAck", - "this.current", - "netascii", - "/", - " 2 Access violation.\n 3 Disk full or allocation exceeded.\n 4 Illegal TFTP operation.\n 5 Unknown transfer ID.\n 6 File already exists.\n 7 No such user.\n", - "tftp", - "________________________________________________________", - "client", - "players", - "PlayerList", - "Maps", - "this.query", - "playerlist", - "name", - "this", - "plugins", - ".emit", - ".on", - "plugin", - "requirePlugin", - "require", - "!!(", - "(fl.pop())", - "fl.pop()", - "spec.pop()", - "spec", - "Is", - "spectator", - "self", - "this", - "console", - "ingame", - "shift", - "plugin", - "ready", - "file", - "Connection", - "\\\\", - "/", - " /##################\\\\');", - "function", - "s", - "loadPlugins", - " self.loadPlugins();\n", - "loadPlugins", - " self.loadPlugins();\n self.loadPlugins();\n self.loadPlugins();\n self.loadPlugins();\n self.loadPlugins();\n", - " self.loadPlugins();\n self.loadPlugins();\n self.loadPlugins();\n self.loadPlugins();\n", - " self.loadPlugins();\n", - "loadPlugins", - "function", - "commands", - "without", - ".", - "*", - "ctrl+b", - "Plugin", - "password", - "config.U", - "config.I", - "config.P", - "\n\n //return;\n setTimeout(function () {\n console.log(\"Exiting!\");\n client.terminate();\n }, 1000);", - " [\"SuperAdmin\", \"SuperAdmin\"], function(err, result) {\n if (err) {\n console.log(err);\n } else {\n if (result === true)\n console.log(\"Authenticated!\");\n }\n });\n \n client.methodCall(\"EnableCallbacks\", [true], function(err, res) {\n console.log(err, res);\n });\n\n //return;\n setTimeout(function () {\n console.log(\"Exiting!\");\n client.terminate();\n }, 1000);\n}", - " });" - ], - "highlight": true, - "in_selection": false, - "preserve_case": false, - "regex": false, - "replace_history": - [ - "-", - "config.u", - "config.i", - "config.p" - ], - "reverse": false, - "show_context": true, - "use_buffer2": true, - "whole_word": false, - "wrap": true - }, - "groups": - [ - { - "selected": 3, - "sheets": - [ - { - "buffer": 0, - "file": "package.json", - "settings": - { - "buffer_size": 242, - "regions": - { - }, - "selection": - [ - [ - 242, - 242 - ] - ], - "settings": - { - "auto_name": "package.json", - "syntax": "Packages/JavaScript/JSON.tmLanguage" - }, - "translation.x": 0.0, - "translation.y": 0.0, - "zoom_level": 1.0 - }, - "type": "text" - }, - { - "buffer": 1, - "file": "lib/tftp.js", - "settings": - { - "buffer_size": 7942, - "regions": - { - }, - "selection": - [ - [ - 1556, - 1556 - ] - ], - "settings": - { - "auto_name": "tftp.js", - "syntax": "Packages/JavaScript/JavaScript.tmLanguage", - "translate_tabs_to_spaces": false - }, - "translation.x": 0.0, - "translation.y": 2077.0, - "zoom_level": 1.0 - }, - "type": "text" - }, - { - "buffer": 2, - "file": "bin/tftp.js", - "settings": - { - "buffer_size": 2683, - "regions": - { - }, - "selection": - [ - [ - 2608, - 2640 - ] - ], - "settings": - { - "syntax": "Packages/JavaScript/JavaScript.tmLanguage", - "translate_tabs_to_spaces": false - }, - "translation.x": 0.0, - "translation.y": 924.0, - "zoom_level": 1.0 - }, - "type": "text" - }, - { - "buffer": 3, - "file": "README.md", - "settings": - { - "buffer_size": 1790, - "regions": - { - }, - "selection": - [ - [ - 1643, - 1643 - ] - ], - "settings": - { - "auto_name": "README.md", - "syntax": "Packages/Markdown/Markdown.tmLanguage" - }, - "translation.x": 0.0, - "translation.y": 168.0, - "zoom_level": 1.0 - }, - "type": "text" - } - ] - } - ], - "incremental_find": - { - "height": 0.0 - }, - "input": - { - "height": 30.0 - }, - "layout": - { - "cells": - [ - [ - 0, - 0, - 1, - 1 - ] - ], - "cols": - [ - 0.0, - 1.0 - ], - "rows": - [ - 0.0, - 1.0 - ] - }, - "menu_visible": true, - "output.exec": - { - "height": 248.0 - }, - "output.git": - { - "height": 545.0 - }, - "replace": - { - "height": 0.0 - }, - "save_all_on_build": true, - "select_file": - { - "height": 0.0, - "selected_items": - [ - [ - "c", - "JsControl.js" - ], - [ - "clien", - "lib/client.js" - ], - [ - ".git", - ".gitignore" - ], - [ - "packa", - "package.json" - ] - ], - "width": 0.0 - }, - "select_project": - { - "height": 500.0, - "selected_items": - [ - ], - "width": 380.0 - }, - "show_minimap": true, - "show_open_files": false, - "show_tabs": true, - "side_bar_visible": true, - "side_bar_width": 212.0, - "status_bar_visible": true -} diff --git a/tftp/node_modules/tftp-client/bin/tftp.js b/tftp/node_modules/tftp-client/bin/tftp.js deleted file mode 100755 index e48a173..0000000 --- a/tftp/node_modules/tftp-client/bin/tftp.js +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env node - -// Require needed modules -var TFTP = require('..'), // The tftp-client module - fs = require('fs'), // Simple wrappers around standard POSIX functions - path = require('path'); // Contains utilities for handling and transforming file paths - -/**********************\ -|* Validate arguments *| -\**********************/ - -// Too few arguments (node + path_to_this_file + host + cmd + file = 5) -if (process.argv.length < 5) { - // Print usage, and exit - console.log('Needs atleast 3 arguments (you had %d)', process.argv.length-2); - console.log(''); - printUsage(true); -} - -// Grab arguments -var host = process.argv[2]; -var cmd = process.argv[3]; -var file = process.argv[4]; -var port = process.argv[5] || 69; // Port defaults to 69 if omitted - -// If cmd is neither read nor write, print usage & exit -if (['read', 'write'].indexOf(cmd)===-1) { - console.log('Command must be read or write (you had %s)', cmd); - printUsage(true); -} - -/*******************\ -|* Validation done *| -\*******************/ - -// Create the client -var client = new TFTP(port, host); - -var basename = path.basename(file); - -/********\ -|* READ *| -\********/ -if (cmd == 'read') { - // Read from server - client.read(basename, function(err, data) { - // If error, output some error message - if (err) { - console.error('Oh noes! Error while reading file from tftp server:'); - console.error(err); - } else { - - // No error, we got the file, lets write it - - fs.writeFile(file, data, function (err) { - - // If error, output some error message - if (err) { - console.error('Dang it! Error while writing file!'); - console.error(err); - } else { - - // No error, the file has been written! - - console.log('File saved (%d bytes)', data.length); - } - }); - } - }); -} -/*********\ -|* WRITE *| -\*********/ -else if (cmd == 'write') { - // If file does not exist, print error and usage & exit - if (!fs.existsSync(file)) { - console.log('File (%s) does not exist!', file); - printUsage(true); - } - - // Read file first, then send to server - var data = fs.readFileSync(file); - - client.write(basename, data, function (err, bytes) { - if (err) { - console.error('ERROR:'); - console.error(err); - return; - } - - console.log('File sent (%d bytes)', bytes); - }); -} else { - console.log('???HOW DID YOU GET HERE???'); -} - -/** - * Prints usage - how to use tftp-client - * @param {boolean} exit Wether it sould exit the process - */ -function printUsage(exit) { - console.log('Usage:'); - console.log(' tftp-client (read|write) []'); - console.log(''); - console.log('Example:'); - console.log(' tftp-client localhost read 1.txt'); - - if (exit===true) - process.exit(0); -} \ No newline at end of file diff --git a/tftp/node_modules/tftp-client/lib/tftp.js b/tftp/node_modules/tftp-client/lib/tftp.js deleted file mode 100644 index 4029627..0000000 --- a/tftp/node_modules/tftp-client/lib/tftp.js +++ /dev/null @@ -1,457 +0,0 @@ -var dgram = require('dgram'); // UDP (datagram) - -// Timeout for ack/data packet -var TIMEOUT = 5000; // 5 seconds -// Max retransmits if timeout -var MAX_RETRANSMITS = 3; - -// type: Opcode -var types = { - 'rrq': 1, // Read ReQuest - 'wrq': 2, // Write ReQuest - 'data':3, - 'ack': 4, - 'err': 5, - - // aliases: - 'read':1, - 'write':2 -} - -// Error strings ([errorCode] = errorString) -var errors = [ - 'Not defined, see error message (if any).', - 'File not found.', - 'Access violation.', - 'Disk full or allocation exceeded.', - 'Illegal TFTP operation.', - 'Unknown transfer ID.', - 'File already exists.', - 'No such user.' -]; - -/** - * Constructor - * @param {Number} port Port the tftp server is listening to - * @param {String} ip Ip or hostname of the tftp server - */ -var TFTP = module.exports = function(port, ip) { - this.ip = ip || '127.0.0.1'; - this.port = port || 69; - - // Hold the current operation - this.current = false; - // Holds the queue of the next operations - this.queue = []; - - // Client will be created when needed - this.client = null; - - // Display debug messages? - this.debug = false; -} - -TFTP.prototype.createClient = function() { - if (this.client !== null) - return; - - // We need this inside onMessage... - var self = this; - - // Called when getting an message from the server - var onMessage = function(msg, rinfo) { - - // Type of message (see `types` above) - var type = msg.readUInt16BE(0); - - switch (type) { - // Data - Respond with Ack - case types.data: - var block = msg.readUInt16BE(2); - var data = msg.slice(4); // From byte 4 is data - - if (self.debug) { - console.log('> Received data. Block#: %d Bytes: %d', block, data.length); - console.log('< Sending ACK. Block#: %d', block); - } - - // Concat the two buffers - self.current.data = Buffer.concat([self.current.data, data]); - - // Create and send ACK packet - var ack = createAck(block); - self.send(ack); - - // If less than 512 bytes were received, it's the end... - if (data.length < 512) { - // Send the data to the callback - self.current.callback(null, self.current.data); - - // Go to next operation in queue - self.next(); - } - break; - // Ack - Respond with Data - case types.ack: - var block = msg.readUInt16BE(2); - - if (self.debug) - console.log('> Received ACK. Block#: %d', block); - - // If this is the ack for the last block - if (block == self.current.blocks) { - // Send callback - self.current.callback(null, self.current.data.length); - - // Go to next operation in queue - self.next(); - - // Break out of switch - break; - } - - if (self.debug) - console.log('< Sending data. Block#: %d', block + 1); - - // Create the data packet for the next block of data - var start = 512 * block; - // End is `start + 512`, or end of data, whichever comes first - var end = Math.min(start + 512, self.current.data.length); - var data = self.current.data.slice(start, end); - - var packet = createData(block+1, data); - - // Send data block - self.send(packet); - break; - // Error - case types.err: - // Create new Error(), and send callback - var errorCode = msg.readUInt16BE(2); - var errMsg = msg.toString('ascii', 4, msg.length - 1); - // @TODO: Take errMsg from `errors`, unless code == 0? - var err = new Error(errMsg); - err.code = errorCode; - - if (self.debug) - console.log('> Received Error. code: %d - msg: %s', errorCode, ErrMsg); - - // Callback - self.current.callback(err); - - // Go to next operation in queue - self.next(); - break; - } - } - - // Create socket, and listen to messages - this.client = dgram.createSocket("udp4", onMessage); -}; - -/** - * Shortcut for sending packet to server - * @param {Buffer} buff The buffer to send - * @param {Function} cb Callback - (err, bytes) - */ -TFTP.prototype.send = function(buff, cb) { - if (typeof cb !== 'function') cb = function() {}; - - // We need this later - var self = this; - - // Create function of sending this packet so that we can call it again on timeout - var send = function() { - self.client.send(buff, 0, buff.length, self.port, self.ip, cb); - }; - // Send the packet already - send(); - - var onTimeout = function() { - // If we have retransmitted less than MAX_RETRANSMITS - if (MAX_RETRANSMITS > ++self.current.timeout.retransmits) { - - if (self.debug) - console.log('! Timeout - Retransmitting (%d bytes)', buff.length); - - // Send the packet again - send(); - - // Set a new timeout for the packet we just sent - self.current.timeout.id = setTimeout(onTimeout, TIMEOUT); - } - - // If we sent too many retransmitts, the remote server did not respond... - else { - if (self.debug) - console.log('! Timeout - End'); - - // Create error - var err = new Error("Timeout"); - err.code = 0; - - self.current.callback(err); - // Reset current, and check queue - (no answer from server) - self.next(); - } - } - - // If there is a timeout, clear the timeout - if (this.current.timeout) - clearTimeout(this.current.timeout.id); - - // Create a timeout object where we store information about this timeout - this.current.timeout = { - id: setTimeout(onTimeout, TIMEOUT), - retransmits: 0 - } -}; - -/** - * Goes to next item in queue (if any). Same as `check()`, but clears current first - */ -TFTP.prototype.next = function() { - // Has to clear any timeout - if (this.current && this.current.timeout) - clearTimeout(this.current.timeout.id); - - // Reset current, and check queue - this.current = false; - this.check(); -}; - -/** - * Checks the Queue. - * If no operation is currently active, go to the next item in the queue (if any). - */ -TFTP.prototype.check = function() { - // If there currently is an active operation - // Or if the queue is empty, just return - if (this.current !== false) - return; - - // If there is nothing running, and the queue is empty - if (this.queue.length == 0) { - // Close client - this.client.close(); - return; - } else { - // Create client - this.createClient(); - } - - // Take the first item in queue - this.current = this.queue.shift(); - - // We need this later - var self = this; - - - if (self.debug) - console.log('< Sending request'); - - // Create the request... - var buff = createRequest(this.current.type, this.current.filename); - // Send the request - this.send(buff, function(err, bytes) { - // If there was an error sending the packet - if (err) { - // Create Error message - var err = new Error(['Error when sending ', - self.current.type, - ' request for ', - self.current.filename].join()); - - // Send error to the callback of the current operation - self.current.callback(err); - - // Reset current - self.current = false; - - // Then check queue - self.check(); - } - }); -}; - -/** - * Sends a file to the server - * @param {String} filename File to send - * @param {Buffer} data The data to write/send to the server - * @param {Function} cb Callback - (err) - */ -TFTP.prototype.write = function(filename, data, cb) { - if (typeof cb !== 'function') cb = function() {}; // Default cb to an empty function - if (!Buffer.isBuffer(data)) data = new Buffer(data); // If data is not a Buffer, make it a buffer - - // Item to put into the queue - var queueItem = { - type: 'write', - filename: filename, - callback: cb, - data: data, - blocks: Math.ceil(data.length / 512) // Number of blocks to transfer data. - // When we receive an ACK with this number, the transfer is finished - }; - - // Push the queueItem to the end of the queue. - this.queue.push(queueItem); - - // Check the queue... - this.check(); -}; - -/** - * Reads a file off the server - * @param {String} filename File to read from server - * @param {Function} cb Callback - (err, data) - */ -TFTP.prototype.read = function(filename, cb) { - if (typeof cb !== 'function') cb = function() {}; // Default cb to an empty function - - // Item to put into the queue - var queueItem = { - type: 'read', - filename: filename, - callback: cb, - data: new Buffer(0) // Buffer of size 0 which will be filled up by onMessage - }; - - // Push the queueItem to the end of the queue. - this.queue.push(queueItem); - - // Check the queue... - this.check(); -}; - -/** - * Creates a buffer for a request. - - 2 bytes string 1 byte string 1 byte - ------------------------------------------------ - | Opcode | Filename | 0 | Mode | 0 | - ------------------------------------------------ - - * @param {String|Number} type Int Opcode, or String (read|write|rrq|wrq) - * @param {String} filename Filename to add in the request - * @param {String} mode optional Mode (netascii|octet|email) - Defaults to octet - * @return {Buffer} The Buffer - */ -function createRequest(type, filename, mode) { - // Figure out the opcode for the type - if (typeof type === 'string') { - type = type.toLowerCase(); - - // If it exists in the types object, we found it - if (types.hasOwnProperty(type)) - type = types[type]; - // If not, we dno what type - else - throw 'Unknown type (' + type + ')'; - } - // Not a string, nor a number, then we dno what type of request it is... - else if (typeof type !== 'number') - throw 'Unknown type (' + type + ')'; - - // Default mode to 'octet' - mode = mode || 'octet'; - - // Calculate the length of the buffer - // mode (2 byte opcode) + length of filename + 1 null byte + length of mode + 1 null byte. - var buffLen = 4 + filename.length + mode.length; - - // Create the buffer - var buff = new Buffer(buffLen); - // Write mode (as unsigned 16 bit integer) on offset 0 - buff.writeUInt16BE(type, 0); - // Write filename as ascii on offset 2 - buff.write(filename, 2, 'ascii'); - // Write mode as ascii on offset filename.length + 3 (type + filename null termination) - buff.write(mode, 2 + filename.length + 1, 'ascii'); - - // Make sure the ends of the strings are null - buff[2 + filename.length] = buff[buffLen - 1] = 0; - - // Return the new buffer - return buff; -} - -/** - * Creates a buffer for a data packet - - 2 bytes 2 bytes n bytes - ---------------------------------- - | Opcode | Block # | Data | - ---------------------------------- - - * @param {Number} blockNumber Which block of the transaction it is - * @param {String} data The data to send - * @return {Buffer} The Buffer - */ -function createData(blockNumber, data) { - var type = types['data']; - - // Type + blocknumber + length of data(max 512) - var dataLen = Math.min(data.length, 512); - var buffLen = 4 + dataLen; - - var buff = new Buffer(buffLen); - - buff.writeUInt16BE(type, 0); // Type as UInt16BE on offset: 0 - buff.writeUInt16BE(blockNumber, 2); // BlockNumber as UInt16BE on offset: 2 - // Copy `data` into buff on offset 4. bytes 0 to 512 from `data`. - data.copy(buff, 4, 0, dataLen); // targetBuffer, targetStart, sourceStart, sourceEnd - - return buff; -} - -/** - * Creates a buffer for a ACK packet - - 2 bytes 2 bytes - --------------------- - | Opcode | Block # | - --------------------- - - * @param {Number} blockNumber Which block to ack - * @return {Buffer} The Buffer - */ -function createAck(blockNumber) { - var type = types['ack']; - - var buff = new Buffer(4); - buff.writeUInt16BE(type, 0); // Type as UInt16BE on offset: 0 - buff.writeUInt16BE(blockNumber, 2); // BlockNumber as UInt16BE on offset: 2 - - return buff; -} - -/** - * Creates a buffer for an ERROR packet - - 2 bytes 2 bytes string 1 byte - ----------------------------------------- - | Opcode | ErrorCode | ErrMsg | 0 | - ----------------------------------------- - - * @param {Number} code ErrorCode - * @param {String} msg Optional message - defaults to the message of the error code - * @return {Buffer} The Buffer - */ -function createError(code, msg) { - // Default error message to the error message for the code (defined on top) - msg = msg || errors[code]; - if (typeof msg !== 'string') msg = ''; - - var type = types['error']; - - var buffLen = 4 + msg.length + 1; - - var buff = new Buffer(buffLen); - buff.writeUInt16BE(type, 0); // Type as UInt16BE on offset: 0 - buff.writeUInt16BE(code, 2); // ErrorCode as UInt16BE on offset: 2 - buff.write(msg, 4, 'ascii'); // ErrMsg as ascii string on offset: 4 - buff[buffLen - 1] = 0; // Last byte is 0 - - return buff; -} diff --git a/tftp/node_modules/tftp-client/package.json b/tftp/node_modules/tftp-client/package.json deleted file mode 100644 index f3a63be..0000000 --- a/tftp/node_modules/tftp-client/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "tftp-client", - "version": "0.2.1", - "description": "Very simple TFTP client", - "keywords": [ - "tftp" - ], - "author": { - "name": "MiniGod" - }, - "repository": { - "type": "git", - "url": "http://github.com/MiniGod/TFTP-Client" - }, - "main": "./lib/tftp.js", - "bin": { - "tftp-client": "./bin/tftp.js" - }, - "readme": "# TFTP-Client\r\n\r\nA simple TFTP client for Node.Js. \r\n*Should not be used in production - first of all: this module is at an early stage (written in less than 12 hours), second: tftp is terrible*\r\n\r\n## Install\r\n\r\n### As a module\r\n`npm install tftp-client`\r\n\r\n### As CLI\r\n`npm install -g tftp-client`\r\n\r\n## Usage\r\n\r\n### Module\r\n\r\n`var client = new TFTP(port, client)` to create a new client.\r\n\r\n`client.read(filename, callback)` to **read** from the server. \r\n ~ The Callback is passed 2 arguments `(err, data)`, where `data` is the contents of the file. \r\n\r\n`client.write(filename, data, callback)` to **write** to the server, where `data` is the contents of the file. \r\n ~ The callback is passed 2 arguments `(err, bytes)`, where `bytes` is the number of bytes sent. \r\n\r\n**Simple read example:**\r\n\r\n```javascript\r\nvar TFTP = require('tftp-client');\r\n\r\n// Initialize the tftp client\r\nvar client = new TFTP(69, 'localhost');\r\n\r\n// Read 1.txt from the server\r\nclient.read('1.txt', function (err, data) {\r\n\tif (err) {\r\n\t\tconsole.error('ERROR:');\r\n\t\tconsole.error(err);\r\n\t\treturn;\r\n\t}\r\n\r\n\tconsole.log('Got data (%d bytes). First 100 bytes:', data.length);\r\n\tconsole.log(data.toString('utf8', 0, 100));\r\n});\r\n```\r\n\r\n### Command line\r\n\r\nTo install the tftp-client as CLI, run `npm install -g tftp-client`.\r\n\r\n`tftp-client (read|write) []`\r\n* hostname - Hostname of tftp server\r\n* read|write - Wether you want to read or write\r\n* filename - Path to the file you want to read or write\r\n* port - Optional. Defaults to 69\r\n\r\n**Example**:\r\n`tftp-client localhost read 1.txt`\r\n\r\n## TODO\r\n\r\n- Error packets - [RFC](http://tools.ietf.org/html/rfc1350#page-8). (implemented, but not tested)\r\n- Do the initial connection as defined in section 4 (TID's: port numbers from request ack) - [RFC](http://tools.ietf.org/html/rfc1350#section-4).\r\n- Currently, any DATA or ACK packet is responded to. Eg. An ACK packet will get a `DATA` response. There is not check for the block numbers to be in order.\r\n", - "readmeFilename": "README.md", - "_id": "tftp-client@0.2.1", - "dist": { - "shasum": "b66ceee832562b8a03ad616b40e3470f5dbd68c0" - }, - "_from": "tftp-client" -}