Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-scola committed Oct 5, 2017
1 parent 695a15d commit a839c1b
Show file tree
Hide file tree
Showing 55 changed files with 4,559 additions and 2 deletions.
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Compile time
#
*.o
.deps/
.libs/
*.l[ao]

#
# Tests
#
*-test-vector-*.sh

#
# Autotools
#
lt*.m4
shtool
stamp-h1
libtool*
Makefile
config.h*
configure
build-aux/
aclocal.m4
config.log
Makefile.in
config.status

#
# Generated binaries
#
grc-sign
grc-verify
grc-keygen
grenache-get
grenache-put
grenache-keygen

#
# Distribution
#
*.tar.*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ed25519"]
path = ed25519
url = https://github.com/orlp/ed25519.git
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ChangeLog is auto-generated when releasing.
If you are seeing this, use 'git log' for a detailed list of changes.
50 changes: 50 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
############################################################################
# This file is part of Grenache Command Line Interface. #
# #
# Copyright (C) 2017 Davide Scola <[email protected]> #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or #
# implied. See the License for the specific language governing permissions #
# and limitations under the License. #
############################################################################

ACLOCAL_AMFLAGS = -I m4

GRC_SUBDIRS = . src tests

SUBDIRS = $(GRC_SUBDIRS)
DIST_SUBDIRS = $(GRC_SUBDIRS) include m4

@GENERATE_CHANGELOG_RULES@

EXTRA_DIST = \
LICENSE \
README.md \
autogen.sh \
shtool

DISTCLEANFILES = \
config.h.in~

MAINTAINERCLEANFILES = \
$(DISTCLEANFILES) \
README

dist-hook: dist-ChangeLog
cp -fpR $(top_srcdir)/ed25519 $(distdir)
$(RM) -rf $(distdir)/ed25519/.git

maintainer-clean-local: maintainer-clean-local-check

maintainer-clean-local-check:
-$(RM) $(distdir).tar.xz

.PHONY: maintainer-clean-local-check
126 changes: 124 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,124 @@
# grenache-cli
The Grenache Command Line Interface.
# Grenache CLI

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

* [Introduction](#introduction)
* [Prerequisites](#prerequisites)
* [Install](#install)
* [Initialize](#initialize)
* [Store items to the DHT](#store-items-to-the-dht)
* [Immutable items](#immutable-items)
* [Mutable items](#mutable-items)
* [Retreive items from the DHT](#retreive-items-from-the-dht)
* [Lookup peers](#lookup-peers)
* [Announce services](#announce-services)
* [Maintainers](#maintainers)


## Introduction

The **Grenache** **C**ommand **L**ine **I**nterface is a set of tools to use the [grenache-grape](https://github.com/bitfinexcom/grenache-grape) suite directly from your command line. Using this set of tools you can create fancy scripts that communicate directly with the DHT.


## Prerequisites

Be sure that your version of [grenache-grape](https://github.com/bitfinexcom/grenache-grape) supports the mutable items (see pull request [#35](https://github.com/bitfinexcom/grenache-grape/pull/35)).


## Install

Briefly, the shell command

```bash
./configure && make && make install
```

should configure, build and install this package.


## Initialize

Before start using this set of tools you need to initialize the `granache-cli` environment; use:

```bash
grenache-keygen
```

This will also generate your key pair that will be used when _mutable_ items are stored to the DHT. This is a one time only task but you can regenerate your key pair at any time if you want to.


## Store items to the DHT

The `grenache-put` command writes an arbitrary payload to the DHT (see [BEP 44](http://bittorrent.org/beps/bep_0044.html) for more information). There are two types of items you can store to the DHT; the _immutable_ items and the _mutable_ ones. In any case, you will get the key under which the item has been stored.

### Immutable items

_Immutable_ items cannot be modified, thus there is no need to authenticate the origin of them. This makes _immutable_ items simple. To write an _immutable_ item to the DHT simply run something like this:

```bash
grenache-put "$(uname -n)"
```

### Mutable items

_Mutable_ items can be updated, without changing their DHT keys. In order to create your key pair, see `grenache-keygen`. To write a _mutable_ item to the DHT simply run something like this:

```bash
grenache-put --mutable "$(uptime -p)"
```

In order to support a single key being used to store separate items in the DHT, an optional salt can be specified in the put request of _mutable_ items:

```bash
grenache-put --mutable --salt 'sys:mem:available' "$(awk '/^MemAvailable:/ { print $2 "Ki" }' < /proc/meminfo)"
```

Note that `grenache-put` is agnostic and it will treat your payload as a **single string**. Other useful options are `-n` or `--number` that will let you set the _sequence number_ to use in your request and `-c` or `--cas` that let you use the _compare and swap_ feature. See

```bash
grenache-put --help
```

to retrieve the complete options list.


## Retreive items from the DHT

The `grenache-get` command reads a data record from the DHT (see [BEP 44](http://bittorrent.org/beps/bep_0044.html) for more information). There is no differences in retreiving a _mutable_ or an _immutable_ item; on both cases the key returned by the *PUT* request must be provided. In any case, `grenache-get` validates the payload it receive; this will ensure that the _key_ provided really match the payload and, in case of a _mutable_ item, that the signature is correct. This will protect you from evil nodes on the network. To read an item from the DHT simply run something like this:

```bash
grenache-get '81c2a8157780989af9a16661324fafbd7803877d'
```

For example, you can format the previously stored available memory amount using something like this:

```bash
numfmt --from=auto --to=iec-i < <(
grenache-get '81c2a8157780989af9a16661324fafbd7803877d'
)
```

You can also retrieve the raw packet received from the network using the `-r` switch or its long form `--raw`. See

```bash
grenache-get --help
```

to retrieve the complete options list.


## Lookup peers

Coming soon...


## Announce services

Coming soon...


## Maintainers

Current maintainers:

* Davide Scola - [email protected]
34 changes: 34 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
############################################################################
# This file is part of Grenache Command Line Interface. #
# #
# Copyright (C) 2017 Davide Scola <[email protected]> #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or #
# implied. See the License for the specific language governing permissions #
# and limitations under the License. #
############################################################################

case "${1}" in
'--reverse')
[[ -x configure ]] && ./configure --enable-maintainer-mode
[[ -f Makefile ]] && make maintainer-clean
rm -rf build-aux/
rm -f {aclocal.m4,config.h.in,configure,shtool}
find . -type f -iregex '.*Makefile\.in$' -print0 | xargs -r0 rm -f
;;
* )
autoreconf --force --install --include 'm4'
[[ -x shtool ]] || shtoolize -q 'echo'
[[ -d autom4te.cache ]] && rm -rf autom4te.cache
;;
esac

Loading

0 comments on commit a839c1b

Please sign in to comment.