Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"node": true,
"es2021": true,
"jest": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {}
}
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- run: npm install
- run: npm run lint
- run: npm run format -- --check
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
package-lock.json
node_modules
ixp.all.js
zz.js
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
84 changes: 0 additions & 84 deletions 00ixputil_test.js

This file was deleted.

33 changes: 0 additions & 33 deletions Gruntfile.js

This file was deleted.

44 changes: 13 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
# 9pJSON

A new Javascript implementation of the 9p protocol.
Unlike most other implementations this one decouples the marshalling.
In this way we can put classic 9p2000 packets on the wire,
or JSON (9pJSON). Use as a module for node.js, or in a web page
(ixp.all.js).
[![CI](https://github.com/rsbohn/9pJSON/actions/workflows/ci.yml/badge.svg)](https://github.com/rsbohn/9pJSON/actions/workflows/ci.yml)

The node.js test suite runs with grunt. Please npm install -g 'grunt-cli' first,
then use npm install in this directory. It should install a current version of
the actual 'grunt' and associated modules.
A new Javascript implementation of the 9p protocol. Unlike most other implementations this one decouples the marshalling. In this way we can put classic 9p2000 packets on the wire, or JSON (9pJSON). Use as a module for node.js, or in a web page (ixp.all.js).

For 'over-the-wire' calls you need to build a packet according to the formats
in ixp.js:packets[] and send it to service.answer(). You'll get a response packet
(as a javascript object). Within your program you can make direct protocol
function calls, "service.Tattach({...})" for example.
### Node.js

## Usage
Install dependencies with `npm install`.
Run `npm run lint` to lint the code, `npm run format` to apply formatting, and `npm test` to run the Jest suite.

### Browser
For 'over-the-wire' calls you need to build a packet according to the formats in ixp.js:packets[] and send it to service.answer(). You'll get a response packet (as a javascript object). Within your program you can make direct protocol function calls, `service.Tattach({...})` for example.

First run `grunt concat` to build 9pJSON.all.js, then include it in your .html file.
See proto.html for more information.
## Usage

### Browser
Include dist/ixp.all.js in your HTML file. See proto.html for more information.
### Node.js

Require 9pJSON, then call .Server() or .Client() as needed. Servers will build a file
tree and then respond to requests by calling .answer(packet).
Require 9pJSON, then call .Server() or .Client() as needed. Servers will build a file tree and then respond to requests by calling .answer(packet).

## Contributing

Expand All @@ -35,15 +26,6 @@ Porting any of the following:
* factotum
* secret store

To contribute please fork this repository,
make sure all the tests pass (including jshint),
then submit pull requests.
Code aligned with the project direction
is more likely to be merged
into the master branch.
Unlikely to be accepted: overly complex code,
patches that change multiple features,
patches without tests.

Much of this code is based on https://github.com/aiju/jsdrawterm.
Most of this code was developed using Acme and a 'test first (mostly)' process.
To contribute please fork this repository, make sure the linter, formatter and test suite pass, then submit pull requests. Code aligned with the project direction is more likely to be merged into the master branch. Unlikely to be accepted: overly complex code, patches that change multiple features, patches without tests.

Much of this code is based on https://github.com/aiju/jsdrawterm. Most of this code was developed using Acme and a 'test first (mostly)' process.
18 changes: 12 additions & 6 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// attach, walk, open, read, close
exports.attach = function(service, chain){
var myFid = Math.floor(Math.random()*1024)+1024;
var request = {type:service.msgtype.Tattach, tag:3000, fid:myFid};
exports.attach = function (service, chain) {
var myFid = Math.floor(Math.random() * 1024) + 1024;
var request = { type: service.msgtype.Tattach, tag: 3000, fid: myFid };
var reply = service.answer(request);
chain(request, reply);
reply = service.answer({type:service.msgtype.Tclunk, tag:3000, fid:myFid});
if (reply.type === service.msgtype.Rerror) { throw reply.ename; }
};
reply = service.answer({
type: service.msgtype.Tclunk,
tag: 3000,
fid: myFid,
});
if (reply.type === service.msgtype.Rerror) {
throw reply.ename;
}
};
81 changes: 43 additions & 38 deletions dist/drawchart.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
(function(exports){
var canvas = document.getElementById('catclock');
(function (exports) {
var canvas = document.getElementById('catclock');

Check failure on line 2 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'document' is not defined

exports.points = [12,15,18,21,24];
exports.points = [12, 15, 18, 21, 24];

exports.add = function(x){
exports.points.push(x);
while (exports.points.length > canvas.height) {
exports.points.shift();
}
}
exports.add = function (x) {
exports.points.push(x);
while (exports.points.length > canvas.height) {
exports.points.shift();
}
};

var drawBox = function(cx, y) {
var x = 1;
var g = exports.points.length;
if (y < g) { x = exports.points[g-y];}
var mid = canvas.width/2;
cx.moveTo(mid-x,y);
cx.lineTo(mid+x, y);
cx.stroke();
}
var drawBox = function (cx, y) {
var x = 1;
var g = exports.points.length;
if (y < g) {
x = exports.points[g - y];
}
var mid = canvas.width / 2;
cx.moveTo(mid - x, y);
cx.lineTo(mid + x, y);
cx.stroke();
};

exports.update = function(){
var cx = canvas.getContext('2d');
var height = canvas.height;
canvas.height=canvas.height;
for (x=0; x<height;x++) {
drawBox(cx, height-x);
}
}
exports.update = function () {
var cx = canvas.getContext('2d');
var height = canvas.height;
canvas.height = canvas.height;

Check failure on line 28 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'canvas.height' is assigned to itself
for (x = 0; x < height; x++) {

Check failure on line 29 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'x' is not defined

Check failure on line 29 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'x' is not defined

Check failure on line 29 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'x' is not defined
drawBox(cx, height - x);

Check failure on line 30 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'x' is not defined
}
};

exports.append = function(s){
var max = 8
for (x in s) {
if (x < max) { exports.add(s.charCodeAt(x));}
else { break; }
}
}
exports.append = function (s) {
var max = 8;
for (x in s) {

Check failure on line 36 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'x' is not defined
if (x < max) {

Check failure on line 37 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'x' is not defined
exports.add(s.charCodeAt(x));

Check failure on line 38 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'x' is not defined
} else {
break;
}
}
};

exports.update();
})(typeof(exports)==='undefined' ? this.drawchart={} : exports);
exports.update();
})(typeof exports === 'undefined' ? (this.drawchart = {}) : exports);

function CanvasCtrl($scope, $timeout) {

Check failure on line 48 in dist/drawchart.js

View workflow job for this annotation

GitHub Actions / build

'CanvasCtrl' is defined but never used
var promise;
$scope.tick = function(){
$scope.tick = function () {
drawchart.update();
promise = $timeout($scope.tick, 1000);
}
};
promise = $scope.tick();
}
}
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
var _util = require("./ixputil");
var _ixp = require("./ixp");
var _util = require('./ixputil');
var _ixp = require('./ixp');
_ixp.set_util(_util);

exports.Server = function(){
exports.Server = function () {
var s = _ixp.Service;
s.tree = _ixp.mkroot();
return s;
};

exports.Client = function(){
exports.Client = function () {
var c = {};
return c;
};

//who uses ixp?
exports.ixp = {
tree:{
mkfile: function(s){throw new Error("bang! "+s);}
}
};
tree: {
mkfile: function (s) {
throw new Error('bang! ' + s);
},
},
};
Loading