Cloud messages for Load81

オープン
#32 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
c, lua, redis

調査の方向性

この issue では、listen()、unlisten()、receive()、send() のエントリポイントを定義し、ノンブロッキングソケット上での Redis pub/sub について説明しています。まず、これらのエントリポイントとイベント処理およびソケットのコードを見つけ、次に記載されている API の動作とメッセージキューイングを確認してください。Load81 インスタンスが購読済みのチャネルを介してシリアライズされたメッセージを交換でき、かつ自身のメッセージを受信しなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement

Load81 programs are currently self-contained into a box without the ability to talk with the external world.
Specifically they can't talk with other instances of the same program running in other Load81 instances around the world! What a shame. So what I'm proposing and implementing is a Cloud message service for Load81.

API

A Load81 program listen to channels using the listen() function. Multiple calls to listen are allowed in order to listen to multiple channels, and it is also possible to no longer listen to a given channel using unlisten(). Example:

listen("asteroids")
listen("foo","bar")
unlisten("asteroids")

Every time a message is received the function receive is called. It is important to understand how this works. The normal flow of a Load81 program is to call setup the first time, and then call draw. When the program is listening to one or more channels, the function receive is called before the function draw is called, and is called for all the pending messages currently in the queue, so for instance you may have 5 calls to receive, and finally the call to draw, and so forth.

This is how the function receive is defined in a program:

function receive(sender,channel,msg)
    ....
end

The three arguments are:

  • sender: a 40 chars hex string that uniquely identifies the sender instance (this instance ID changes at every run).
  • channel: the channel that received the message.
  • msg: a Lua object (number, string, table, boolean, ...)

You don't receive messages that are sent by your instance.

In order to send messages you simply use:

send("channel",lua_object)

You can send messages to channels you are not listening without problems if you wish.

Implementation

The implementation using a Redis instance running at pubsub.load81.com, with only PUBLISH and SUBSCRIBE commands enabled. The instance is configured to drop clients that reached an output buffer of a few hundred kbytes so that it is not possible to abuse the instance just listening to channels without actually reading data.

Every Load81 instance creates a random identifier at startup, either reading from /dev/urandom or using a mix of time and rand() if urandom is not available.

Messages are send to Redis as <Instance ID>:<MessagePack representation of the Lua object sent>.

Messages are both sent and received using a non blocking socket. At every iteration we read what's new in the socket, and call a function that will put all the entire messages in the queue, parsing the Redis protocol.

From the point of view of sending, we'll try to send messages every time the user calls the send() function in order to minimize latency, but if there is no room on the kernel socket buffer we'll bufferize the write and send it when possible (at the next iteration of the event processor, that is, by default, 30 times per second).

Abuses

From the outside attacker this is a free message hub, but I think it's fine since for instance an IRC server has the same problem.... and I think no one will try to abuse this stuff, at least I hop.

主要言語
C
スター
743
フォーク
65
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

antirez/load81 のほかの issue

antirez/load81 の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。