Skip to content

Commit

Permalink
extra
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Dec 3, 2023
2 parents b73418f + 87fd011 commit 015a5fd
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 129 deletions.
12 changes: 0 additions & 12 deletions .github/FUNDING.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
- uses: actions/checkout@v2
- uses: erlef/setup-elixir@v1
with:
otp-version: 23.x
elixir-version: 1.9.x
otp-version: 24.x
elixir-version: 1.11.x
- name: Dependencies
run: |
mix local.rebar --force
Expand Down
5 changes: 2 additions & 3 deletions COC.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
N2O User Agreement
==================
# N2O User Agreement

## 1. Motivation

Expand Down Expand Up @@ -42,7 +41,7 @@ Talk to @5HT.

## 8. Addressing Grievances

N2O board commitee is higher that @5HT.
N2O board committee is higher that @5HT.

## 9. Scope

Expand Down
4 changes: 1 addition & 3 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Credits
-------
# Credits

* Maxim Sokhatsky — core, shen, windows
* Dmitry Bushmelev — yaws, cowboy
Expand All @@ -13,4 +12,3 @@ Credits
* Yuri Maslovsky — mqtt
* Igor Kharin — k8s, ekka
* Rusty Klophaus — original author

4 changes: 1 addition & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
History
-------
# History

* 4.5 — Basic Messaging with single topic and Echo
* 4.6 — Echo eliminated Basic Filter with req/rep topics
Expand All @@ -12,4 +11,3 @@ History
* 6.3 — arraybuffer in JS client, n2o_pi, fixes, synrc/mqtt drop
* 6.4 — Error handling, minimalisation
* 6.5 — OTP 21.0, n2o.dev, WebSocket ring, /-endpoint for static/WS, Erlang logger

20 changes: 18 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
ISC License
DHARMA License

Copyright (c) 2013—2019 Maxim Sokhatsky <[email protected]>
Copyright (c) 2011—2022 Synrc Research

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

YOU CANNOT USE THIS SOFTWARE IN ANY (PROVABLE BY MONEY TRACE)
PROCESS CHAIN OF EXTERMINATING UKRAINIANS BY ANY MEANS OF FASCIST
ACTIONS AGAINST OUR TERRITORIAL INTEGRITY, CULTURAL DIVERSITY BY
APPLYING MILITARY INVASIONS, ECONOMICAL WARS, HUMANITARIAN DISASTERS,
ARTFICIAL HOLODOMORS, GENOCIDE, RAPING, LOOTING, ROBBERIES, SPREADING
FAKE INFORMATION, AND OTHER CONTEMPORARY WEAPONS OF WAR AT SCALE
OR IN INVIDIVUAL MANNER.

YOU CANNOT USE THIS SOFTWARE BY ANY MEANS IN INTEREST OF LEGAL
ENTITIES OR INDIVIDUALS WHO IS SUPPORTING NOW OR WAS SUPPORTING
BACK THEN FASCISM, RUSCISM, COMMUNISM, CHAUVINISM, HUMILIATION,
AND OTHER SUPPRESSIVE IDEOLOGIES IN DIFFERENT EXPRESSIONS.

STOP KILLING UKRAINIANS,
THE COUNTER RENDERS TENS OF MILLIONS.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
Expand Down
99 changes: 45 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
N2O: TCP MQTT WebSocket
=======================
# N2O: TCP MQTT WebSocket

[![Actions Status](https://github.com/synrc/n2o/workflows/mix/badge.svg)](https://github.com/synrc/n2o/actions)
[![Build Status](https://travis-ci.com/synrc/n2o.svg?branch=master)](https://travis-ci.com/synrc/n2o)
[![Hex pm](http://img.shields.io/hexpm/v/n2o.svg?style=flat)](https://hex.pm/packages/n2o)
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3D5HT%26type%3Dpatrons&style=flat)](https://patreon.com/5HT)

N2O is an embeddable message protocol loop library for
WebSocket, HTTP, MQTT and TCP servers. It provides basic
features, such as process management, virtual nodes ring for
request processing, sessions, frame encoding, and unified API for external mq and caching services.
N2O is an embeddable message protocol loop library for WebSocket, HTTP, MQTT
and TCP servers. It provides basic features, such as process management,
virtual nodes ring for request processing, sessions, frame encoding, and
unified API for external mq and caching services.

Core Features
-------------
## Core Features

* Purpose: High performance protocol relay
* Endpoints: WebSockets, MQTT, TCP
Expand All @@ -22,34 +19,32 @@ Core Features
* PubSub: GPROC, SYN, PG2
* Formatters: JSON, BERT, ASN.1

Protocol Extensions
-------------------
## Protocol Extensions

* Templates: DTL, <a href="https://nitro.n2o.dev">NITRO</a>
* Abstract Database Layer <a href="https://kvs.n2o.dev">KVS</a>: FS, MNESIA, ROCKSDB, RIAK, REDIS
* Business Processes: <a href="https://bpe.n2o.dev">BPE</a> (BPMN 2.0), SCM, ERP, CRM
* HTTP API: <a href="https://rest.n2o.dev">REST</a> (proplist/JSON)
* <a href="https://active.n2o.dev">ACTIVE</a> Reloading: Linux, Windows, Mac
* Templates: DTL, [NITRO](https://nitro.n2o.dev)
* Abstract Database Layer [KVS](https://kvs.n2o.dev"): FS, MNESIA, ROCKSDB,
RIAK, REDIS
* Business Processes: [BPE](https://bpe.n2o.dev) (BPMN 2.0), SCM, ERP, CRM
* HTTP API: [REST](https://rest.n2o.dev) (proplist/JSON)
* [ACTIVE](https://active.n2o.dev) Reloading: GNU/Linux, Windows, macOS

Basic Samples
-------------
* MQTT Chat: <a href="https://review.n2o.dev">REVIEW TT</a> (8000)
* WebSocket Chat: <a href="https://sample.n2o.dev">SAMPLE WS</a> (8001)
## Basic Samples

Enterprise Samples
------------------
* Online Client Bank: <a href="https://fin.erp.uno">BANK</a> (8041)
* Instant Messaging: <a href="https://chat.n2o.dev">CHAT</a> (8042)
* Product Lifecycle Management: <a href="https://plm.erp.uno">PLM</a> (8043)
* MQTT Chat: [REVIEW TT](https://review.n2o.dev) (8000)
* WebSocket Chat: [SAMPLE WS](https://sample.n2o.dev) (8001)

Motivation
----------
## Enterprise Samples

* Online Client Bank: [BANK](https://fin.erp.uno) (8041)
* Instant Messaging: [CHAT](https://chat.n2o.dev) (8042)
* Product Lifecycle Management: [PLM](https://plm.erp.uno) (8043)

## Motivation

N2O was created to bring clarity and sanity to software development.
The distribution model is per file basis with ISC license.

Kernel
------
## Kernel

The core modules provide OTP start and N2O entry point.

Expand All @@ -58,26 +53,24 @@ The core modules provide OTP start and N2O entry point.
* [n2o_proto](https://ws.n2o.dev/man/n2o_proto.htm) — N2O Loop
* [n2o_ring](https://ws.n2o.dev/man/n2o_ring.htm) — N2O Ring

MQTT
----
## MQTT

MQTT version is implemented as RPC over MQ pattern.
N2O service worker started as ring of virtual nodes each runs N2O loop.

* [n2o_mqtt](https://ws.n2o.dev/man/n2o_mqtt.htm) — N2O MQTT Virtual Node
* [n2o_auth](https://ws.n2o.dev/man/n2o_auth.htm) — N2O Auth

```
$ mad app zero review
$ cd review
$ mad dep com pla rep
$ open http://127.0.0.1:8000
```sh
mad app zero review
cd review
mad dep com pla rep
open http://127.0.0.1:8000
```

WebSocket
---------
## WebSocket

N2O Loop is directly connected and runned inside context of WebSocket handler.
N2O Loop is directly connected and ran inside context of WebSocket handler.
Usually in Erlang we use `syn` or `gproc` OTP message buses.
As such buses are optional in MQTT setup we include bus drivers in WebSocket package.

Expand All @@ -87,15 +80,14 @@ As such buses are optional in MQTT setup we include bus drivers in WebSocket pac
* [n2o_gproc](https://ws.n2o.dev/man/n2o_gproc.htm) — GPROC bus backend
* [n2o_syn](https://ws.n2o.dev/man/n2o_syn.htm) — SYN bus backend

```
$ mad app nitro sample
$ cd sample
$ mad dep com pla rep
$ open https://127.0.0.1:8001/app/index.htm
```sh
mad app nitro sample
cd sample
mad dep com pla rep
open https://127.0.0.1:8001/app/index.htm
```

Protocols
---------
## Protocols

N2O ships with 3 optional protocols.

Expand All @@ -104,8 +96,7 @@ N2O ships with 3 optional protocols.
* [nitro_n2o](https://nitro.n2o.dev/man/nitro_n2o.htm) — Nitrogen Web Framework protocol
* [bpe_n2o](https://bpe.n2o.dev) — Business Process Engine protocol

Services
--------
## Services

Formatters, Sessions, etc. Optional.

Expand All @@ -114,8 +105,7 @@ Formatters, Sessions, etc. Optional.
* [n2o_secret](https://ws.n2o.dev/man/n2o_secret.htm) — AES/GCM-256 encoder/decoder
* [n2o_session](https://ws.n2o.dev/man/n2o_session.htm) — ETS session storage

JavaScript
----------
## JavaScript

* [bert.js](https://ws.n2o.dev/man/bert.js.htm) — BERT encoder/decoder
* [utf8.js](https://ws.n2o.dev/man/utf8.js.htm) — UTF8 encoder/decoder
Expand All @@ -125,8 +115,9 @@ JavaScript
* [n2o.js](https://ws.n2o.dev/man/n2o.js.htm) — N2O protocol loop
* [mq.js](https://ws.n2o.dev/man/mq.js.htm) — MQTT client

Literature
----------
* "N2O: no bullshit sane framework for wild web" [PDF](https://n2o.dev/books/n2o.pdf) (versions 0.11—4.4)
* "N2O BOOK Vol.2 Green Book" [HTML](https://n2o.dev/ua/books/vol.2/index.html) (versions 4.5—8.11)
## Literature

* "N2O: no bullshit sane framework for wild web"
[PDF](https://n2o.dev/books/n2o.pdf) (versions 0.11—4.4)
* "N2O BOOK Vol.2 Green Book" [HTML](https://n2o.dev/ua/books/vol.2/index.html)
(versions 4.5—9.11)
4 changes: 2 additions & 2 deletions include/ftp.hrl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-ifndef(FTP_HRL).
-define(FTP_HRL, true).

-record(ftp, { id=[], sid=[], filename=[], meta=[], size=[], offset=[], block=[], data=[], status=[] }).
-record(ftpack, { id=[], sid=[], filename=[], meta=[], size=[], offset=[], block=[], data=[], status=[] }).
-record(ftp, { id=[], sid=[], filename=[], meta=[], size=[], offset=[], block=[], data=[], status=[], options = []}).
-record(ftpack, { id=[], sid=[], filename=[], meta=[], size=[], offset=[], block=[], data=[], status=[], options = []}).

-endif.
7 changes: 2 additions & 5 deletions lib/ftp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ defmodule N2O.FTP do
:filelib.ensure_dir(filePath)
Supervisor.start_link([], strategy: :one_for_one, name: FTP)

try do
:n2o_pi.stop(:ftp, guid)
catch e -> IO.inspect(e, label: "N2O PI STOP ERROR")
end
try do :n2o_pi.stop(:ftp, guid) catch _,_ -> [] end
initFtp = N2O.ftp(ftp, block: chunk(), offset: 0, data: <<>>)
N2O.pi(
module: FTP,
Expand Down Expand Up @@ -65,7 +62,7 @@ defmodule N2O.FTP do
case :file.write_file(filePath, :erlang.iolist_to_binary(data), [:append, :raw]) do
:ok ->
spawn(fn -> :erlang.send(web_pid, {:direct, {:ftp_finish, finishFtp}}) end)
spawn(fn -> :n2o_pi.stop(:ftp, guid) end)
spawn(fn -> try do :n2o_pi.stop(:ftp, guid) catch _,_ -> [] end end)
{:stop, :normal, finishFtp, N2O.pi(pi, state: {finishFtp, timer})}
{:error, _} = x -> {:reply, x, pi}
end
Expand Down
4 changes: 2 additions & 2 deletions man/n2o.htm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ <h3>CONFIG</h3>
configuration, you may set any implementation for any service.</p>
</section>
<section>
<p>The following configurable services are publically available in <b>n2o</b> module:</p>
<p>The following configurable services are publicly available in <b>n2o</b> module:</p>
</section>
<section>
<h3>CACHE</h3>
Expand Down Expand Up @@ -277,7 +277,7 @@ <h3>FORMAT</h3>
</section>
<section>
<h3>SESSION</h3>
<p>Sessions are stored in issued tokens encripted with AES/GCM-256.
<p>Sessions are stored in issued tokens encrypted with AES/GCM-256.
All session variables are cached in ETS table in the default
implementation <a href="n2o_session.htm">n2o_session</a>.
</p>
Expand Down
9 changes: 7 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
defmodule N2O.Mixfile do
use Mix.Project
def deps, do: [{:ex_doc, ">= 0.0.0", only: :dev}]
def application, do: [mod: {:n2o, []}, applications: [], extra_applications: [:crypto,:xmerl]]
def application(), do:
[
mod: {:n2o, []},
applications: [:xmerl,:ex_doc],
extra_applications: [:crypto]
]

def project do
[
app: :n2o,
version: "8.12.1",
version: "10.8.2",
description: "N2O MQTT TCP WebSocket",
package: package(),
deps: deps()
Expand Down
1 change: 1 addition & 0 deletions priv/bert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// API

function nil() { return { t: 106, v: [] }; }
function tuple() { return { t: 104, v: Array.apply(null, arguments) }; }
function list() { return { t: 108, v: Array.apply(null, arguments) }; }
function map() { return { t: 116, v: Array.apply(null, arguments) }; }
Expand Down
25 changes: 16 additions & 9 deletions priv/ftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,29 @@ var ftp = {
offset: ftp.offset || 0,
block: 1,
total: file.size,
file: file
file: file,
active: false
};
ftp.queue.push(item);
ftp.send(item, '', 1);
return item.id;
},
start: function (id) {
if (ftp.active) { id && (ftp.item(id).autostart = true); return false; }
var item = id ? ftp.item(id) : ftp.next();
if (item) { ftp.active = true; ftp.send_slice(item); }
if (item) {
if (item.active) { id && (item.autostart = true); return false; }
else {item.active = true; ftp.send_slice(item);}
}
},
stop: function (id) {
var item = id ? ftp.item(id) : ftp.next();
if (item) item.active = false;
},
abort: function(id) {
var item = ftp.item(id);
var index = ftp.queue.indexOf(item);
ftp.queue.splice(index, 1);
ftp.active = false;
ftp.start();
if (item) item.active = false;
},
send: function (item, data) {
ws.send(enc(tuple(atom('ftp'),
Expand All @@ -47,7 +53,8 @@ var ftp = {
number(item.offset),
number(item.block || data.byteLength),
bin(data),
bin(item.status || 'send')
bin(item.status || 'send'),
list()
)));
},
send_slice: function (item) {
Expand Down Expand Up @@ -83,9 +90,9 @@ $file.do = function (rsp) {
case 'send':
$file.progress(offset,total);
var item = ftp.item(utf8_arr(rsp.v[1].v));
item.offset = offset;
item.block = block;
(block > 0 && ftp.active) ? ftp.send_slice(item) : ftp.stop(item.id)
if (item) item.offset = offset;
if (item) item.block = block;
(block > 0 && (item && item.active)) ? ftp.send_slice(item) : ftp.stop(item.id)
break;
case 'relay': debugger; if (typeof ftp.relay === 'function') ftp.relay(rsp); break;
}
Expand Down
Loading

0 comments on commit 015a5fd

Please sign in to comment.