Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Programmable policy demo #271

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Draft
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
45 changes: 45 additions & 0 deletions demos/programmable_policy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
45 changes: 45 additions & 0 deletions demos/programmable_policy/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "d8a9f9a52e5af486f80d932e838ee93861ffd863"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
- platform: android
create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
- platform: ios
create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
- platform: linux
create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
- platform: macos
create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
- platform: web
create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
- platform: windows
create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863
base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
236 changes: 236 additions & 0 deletions demos/programmable_policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
# Programmable Policy Demo

This demo is composed of several components, all of which join to create a
real-time simulation of a network with a programmable policy algorithm.

## Demo components

### Nodes

Nodes invoked by the service. In this demo, these nodes are processes
running, but the only external communication is with their own atServer.
In a real environment these nodes could either be provisioned by any regular
means.

There are three types of nodes:

- server
- agent
- client

#### Server nodes

There are four server nodes, they are color coded and each represents a
different type of service. For the purposes of the demo these services have
been kept very simple.

- red: when sent "ping", responds with "pong"
- orange: a basic calculator which responds with the result when sent a math
expression
- yellow: when sent a request responds with some randomly generated IoT data
- green: performs a dice roll and responds with the result of the roll

##### Red Node

Takes a request with a payload of:

```json
{
"message": "ping"
}
```

Responds with

```json
{
"message": "pong"
}
```

##### Orange Node

Takes a request with a payload of:

```json
{
"expression": "<math expression string>"
}
```

Responds with:

```json
{
"result": "<result of math expression>"
}
```

##### Yellow Node

Takes a request with empty payload: `{}`.

Responds with:

```json
{
"temp": "<random float [-30:30]>",
"humidity": "<random float [0:1]>"
}
```

##### Green Node

Takes a request with a payload of:

```json
{
"dice-size": "<optional: positive integer>"
}
```

Responds with:

```json
{
"result": "<positive integer>"
}
```

#### Agent nodes

The agent node may act as both a client and a server. It acts as a server
when speaking with clients, and it acts as a client when speaking with servers.

- violet: an LLM service which takes natural language and uses the orange and
green services to randomly generate numbers (by rolling the dice with green)
and compute math expressions (by using orange). The service then responds
with the result in natural language.

- blue: coming soon

#### Client nodes

There is one type of client node, which takes a list of colors, these are the
types of requests that the client will make with the system.

Client nodes in this demo are simulated, and will periodically make requests
to services that match the configured colors until shutdown.

## Main Demo Driver

A Flutter application serves multiple roles for the sake of the demo.

On the main thread (the application itself), it serves as a front end for
displaying the graph of the network simulation.

On a second thread, in the background, the application also spins up:

- A policy service
- A simulation service

### Flutter application

The Flutter application receives a list of events that occur in the simulated
environment and updates the graph accordingly. The application also receives
logs from all of the nodes and stores them so they can be viewed on a second
screen.

### Policy Service

The policy service takes two kinds of queries:

- Request access: for requesting access to a system / system type
- Check access: for looking up with a particular atSign has the right to access a
particular node

#### Request Access Query

The request access query is used by clients (and agents acting as clients) to
request access to a particular service or service type.

The intent string is `"request"`.

The request payload schema looks like:

```json
{
"atsign": "<String?>",
"color": "<String?>",
"expiry": "<int?>"
}
```

One of either `atsign` or `color` must be provided, if both are provided, then
`atsign` takes priority.

Expiry is an optional timestamp (as milliseconds since epoch) which represents
when the grant will expire. The default expiry (if the grant is accepted)
is 30 minutes from when the policy service processes the request.

The response payload schema for an accepted access request looks like:

```json
{
"granted": true,
"atsign": "<String>",
"expires": "<int>"
}
```

The response payload schema for a rejected access request looks like:

```json
{
"granted": false
}
```

#### Check Access Query

The check access query is used by servers (and agents acting as servers) to
check access for a particular client which has queried it.

The intent string is "check".

The request payload schema is empty `{}`.

> All of the information required by the policy service is automatically
> provided outside of the payload.

The response payload schema for an accepted check request looks like:

```json
{
"granted": true,
}
```

The response payload schema for a rejected check request looks like:

```json
{
"granted": false
}
```

### Simulation Service

The simulation service drives the demo, it randomly creates and removes nodes
from the system. In a real-world environment, this service would not exist.
It only serves the purpose of simulating people and machines interacting with
the network environment.

### atServers Virtual Environment

The atServers Virtual Environment is contained under [setup/](./setup). To start
the virtual environment for the first time, the [setup.sh](setup/setup.sh)
script can be run. It will provision a virtual environment, then activate
the atkeys and store them in [setup/keys/](./setup/keys/).

If the environment is already running and you would like to re-provision it,
run [reset.sh](./setup/reset.sh).

If either `setup.sh` or `reset.sh` fails to generate a set of keys, run
[generate_keys.sh](./setup/generate_keys.sh), this will attempt to activate
any of the atSigns for which there are not keys.
28 changes: 28 additions & 0 deletions demos/programmable_policy/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
13 changes: 13 additions & 0 deletions demos/programmable_policy/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/to/reference-keystore
key.properties
**/*.keystore
**/*.jks
Loading
Loading