Convert nkls' gnunet-docker repo to pygnunetrest

ie. the python code and docker that is only for the GNUnet REST API and
not the docker for building a GNUnet docker image.

Squasing all nkls' commits and appling juga's MR:
https://gitlab.com/nkls_pep/gnunet-docker/-/merge_requests/1
master
nkls 3 years ago committed by juga
commit ddfe1329ee

@ -0,0 +1,24 @@
variables:
DEBIAN_FRONTEND: noninteractive
IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
image: docker:latest
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
build:
timeout: 3h
stage: build
script:
- echo building $IMAGE and releasing as $RELEASE_IMAGE
- docker build -t $IMAGE .
- docker push $IMAGE
- docker tag $IMAGE $RELEASE_IMAGE
- docker push $RELEASE_IMAGE

@ -0,0 +1,57 @@
FROM debian:buster-slim
RUN apt update && apt upgrade -y && \
apt install -y git libtool autoconf autopoint \
build-essential libgcrypt-dev libidn11-dev zlib1g-dev \
libunistring-dev libglpk-dev miniupnpc libextractor-dev \
libjansson-dev libcurl4-gnutls-dev gnutls-bin libsqlite3-dev \
openssl libnss3-tools libopus-dev libpulse-dev libogg-dev \
libargon2-dev libsodium-dev libgnutls28-dev htop wget \
python3-pip nano nmap && pip3 install requests
COPY pygnunetrest pygnunetrest
COPY testdata testdata
WORKDIR /
RUN echo "building libmicrohttpd" && \
/usr/bin/wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.71.tar.gz && \
/bin/tar -xf /libmicrohttpd-0.9.71.tar.gz && \
/bin/rm /libmicrohttpd-0.9.71.tar.gz
WORKDIR /libmicrohttpd-0.9.71
RUN autoreconf -fi && \
./configure --disable-doc --prefix=/opt/libmicrohttpd && \
make -j$(nproc || echo -n 1) && \
make install
WORKDIR /
RUN echo "building gnunet"
RUN /usr/bin/wget http://ftpmirror.gnu.org/gnunet/gnunet-0.13.3.tar.gz && \
/bin/tar -xf /gnunet-0.13.3.tar.gz && \
/bin/rm gnunet-0.13.3.tar.gz
WORKDIR /gnunet-0.13.3
ENV GNUNET_PREFIX=/usr/local
ENV CFLAGS="-g -Wall -O0"
RUN ./configure --prefix=$GNUNET_PREFIX --disable-documentation --enable-logging=verbose --with-microhttpd=/opt/libmicrohttpd && \
/usr/sbin/addgroup gnunet && \
/usr/sbin/addgroup gnunetdns && \
/usr/sbin/adduser --system --home /var/lib/gnunet gnunet && \
/usr/sbin/usermod -aG gnunet root && \
make -j$(nproc || echo -n 1) && \
make install
WORKDIR /
RUN mkdir /gnunet-config
RUN touch /gnunet-config/gnunet.conf
RUN mkdir -p /logs
RUN touch /logs/arm.log
ENV LD_LIBRARY_PATH=/usr/local/lib
COPY docker-entrypoint.sh /opt
ENV PATH="/usr/local/share/bin:$PATH"
ENTRYPOINT ["/opt/docker-entrypoint.sh"]

@ -0,0 +1,2 @@
Docker Image with GNUnet V13.2 on Debian Buster Slim

@ -0,0 +1,3 @@
#!/bin/bash
gnunet-arm -s -c /gnunet-config/gnunet.conf -L EVERYTHING -l /logs/arm.log
exec bash

@ -0,0 +1,8 @@
This is some python code to use GNUnet via the REST API.
Note: You need to have a running GNUnet installation on your machine with REST API for it to work.
Or in the network, it is a REST API.
gnunet.py: The file to import.
example.py Running examples for all functions with many comments.
just run "python3 example.py", no worries ;)

@ -0,0 +1,186 @@
#Examples for the Python GNUnet REST Connector
import gnunet
#make instance of connector,
#without arguments it defaults to localhost, port 7776
print("\nMaking instance of connector")
conn=gnunet.GNUnetConnector()
#it is also possible to specify host and port, for example:
#conn=gnunet.GNUnetConnector("localhost","7771")
#test if connection is possible
print("\nTesting Connector")
if(conn.test()==True):
print("Connection established")
else:
print("Connection not possible")
quit()
#IDENTITIES#
#==========#
#first we create an identity named alice.
#the function createIdentity returns a boolean for success or failure.
print("\nCreating some identities")
idname="alice"
success=conn.createIdentity(idname)
if(success==True):
print("Identity ",idname," created")
else:
print("Error: Identity not created")
#then we create two more identities, bob and carol.
idname="bob"
success=conn.createIdentity(idname)
if(success==True):
print("Identity ",idname," created")
else:
print("Error: Identity not created")
idname="carol"
success=conn.createIdentity(idname)
if(success==True):
print("Identity ",idname," created")
else:
print("Error: Identity not created")
#now we retrieve a list of all existing identities.
#the function returns a list of dictionaries.
print("\nRetrieving identities")
ids=conn.getIdentityList()
for x in ids:
print("Name: ",x["name"],"\nPublic Key: ",x["pubkey"],"\n")
#to retrieve the public key of specific identity, we use this:
pubkey_alice=conn.getIdentityPubkey("alice")
print("Public key of alice: ",pubkey_alice)
#to get the identity name corresponding to a public key, we use this:
name_alice=conn.getIdentityName(pubkey_alice)
print("Name for public key ",pubkey_alice, ": ",name_alice)
#next we change the name of identity "bob" to "dorothy".
print("\Changing name of identity")
from_id="bob"
to_id="dorothy"
success=conn.changeIdentityName("bob","dorothy")
if(success==True):
print("Changed identity ",from_id," to ",to_id)
else:
print("Error: Identity not changed")
#in the end, we delete all created identities.
print("\nDeleting identities")
if(conn.deleteIdentity("alice")):print("deleted alice")
if(conn.deleteIdentity("dorothy")):print("deleted dorothy")
if(conn.deleteIdentity("carol")):print("deleted carol")
#NAMESTORE#
#=========#
#to use the namestore subsystem, we first need an identity (also called 'ego')
print("\nCreating identity for namestore")
idname="emily"
success=conn.createIdentity(idname)
if(success==True):
print("Identity ",idname," created")
else:
print("Error: Identity not created")
#then, we have to make the created identity the default ego of namestore subsystem.
#note: the name of that identity (or ego) is also the name of the zone
print("\nMake identity the namestore default ego")
success=conn.setNamestoreIdentity(idname)
if(success==True):
print(idname," is now the namestore default identity.")
else:
print("Setting namestore default identity failed")
#now we add some namestore entries to the zone.
#syntax is: addNamestoreEntry(zone,name,value,type)
print("\nAdding some namestore entries")
zonename=idname
success1=conn.addNamestoreEntry(zonename,"google","8.8.8.8","A")
success2=conn.addNamestoreEntry(zonename,"pepfoundation","95.128.36.146","A")
success3=conn.addNamestoreEntry(zonename,"gnunet","131.159.74.67","A")
if(success1 and success2 and success3):
print("3 records created")
else:
print("failure creating records")
#we can change existing namestore entries.
print("\nChanging namestore entry")
success=conn.changeNamestoreEntry(zonename,"google","6.6.6.6","A")
if(success):
print("Namestore entry changed")
else:
print("failure changing namestore entry")
#now we show all existing namestore entries.
print("\nRetrieving namestore entries")
entries=conn.getNamestoreEntries(zonename)
for x in entries:
print("\n")
print("Name: ",x["record_name"])
for y in x["data"]:
print("Value: ",y["value"]," Type:",y["record_type"])
#delete all the namestore entries
print("\nDeleting all namestore entries")
success1=conn.deleteNamestoreEntry(zonename,"google")
success2=conn.deleteNamestoreEntry(zonename,"pepfoundation")
success3=conn.deleteNamestoreEntry(zonename,"gnunet")
if(success1 and success2 and success2):
print("Namestore entries successfully deleted")
else:
print("Error deleting namestore entries")
#GNS#
#===#
#first we create a test record with 3 namestore entries.
print("\nCreating namestore entries")
zonename=idname
success1=conn.addNamestoreEntry(zonename,"testrecord","95.128.36.146","A")
success2=conn.addNamestoreEntry(zonename,"testrecord","Notes for the record","TXT")
success3=conn.addNamestoreEntry(zonename,"testrecord","Further notes for the record","TXT")
#success3=True
#forgot why i did this
if(success1 and success2 and success3):
print("3 records created")
else:
print("failure creating records")
#then we retrieve all entries for the test record
print("\nRetrieving GNS records by name")
entries=conn.getGNSValuesOfName(zonename,"testrecord")
print("\n")
print("Record name: ",entries["record_name"])
for x in entries["data"]:
print("Type: ",x["record_type"]," Value: ",x["value"])
#now we only retrieve entries for the test of type "TXT"
print("\nRetrieving GNS records by name and type")
entries=conn.getGNSValuesOfNameAndType(zonename,"testrecord","TXT")
print("\n")
print("Record name: ",entries["record_name"])
for x in entries["data"]:
print("Type: ",x["record_type"]," Value: ",x["value"])
#in the end, we delete the test record.
print("\nDeleting test record")
success=conn.deleteNamestoreEntry(zonename,"testrecord")
if(success):
print("Namestore entry successfully deleted")
else:
print("Error deleting namestore entries")

@ -0,0 +1,166 @@
import requests
import json
import socket
class GNUnetConnector:
def __init__(self,host="localhost",port="7776"):
self.host=host
self.port=port
def test(self):
#check if port is open
#not the best solution, it should better check if REST responds \
#and not only if port is listening
testsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
testlocation = (self.host, int(self.port))
testresult = testsocket.connect_ex(testlocation)
testsocket.close()
if testresult == 0:
return True
else:
return False
# Identity Section
def getIdentityList(self):
#returns a list of all identities
requeststring="http://"+self.host+":" \
+self.port+"/identity/"
respdata=requests.get(requeststring).json()
val=json.loads(json.dumps(respdata))
return(val)
def getIdentityPubkey(self,thename):
#returns the public key of an identity specified by name
requeststring="http://"+self.host+":" \
+self.port+"/identity/name/"+thename
respdata=requests.get(requeststring).json()
val=json.loads(json.dumps(respdata))
return(val["pubkey"])
def getIdentityName(self,thepubkey):
#returns the name of an identity specified by public key
requeststring="http://"+self.host+":" \
+self.port+"/identity/pubkey/"+thepubkey
respdata=requests.get(requeststring).json()
val=json.loads(json.dumps(respdata))
return(val["name"])
def getNamestoreIdentity(self):
#returns the default identity of subsystem 'namestore'
requeststring="http://"+self.host+":" \
+self.port+"/identity/subsystem/namestore"
respdata=requests.get(requeststring).json()
val=json.loads(json.dumps(respdata))
return(val["name"])
def createIdentity(self,thename):
#creates Identy, returns True if successful, False if not
requeststring="http://"+self.host+":" \
+self.port+"/identity"
datadict={"name": thename}
dataparams=json.dumps(datadict)
respdata=requests.post(requeststring,data=dataparams)
if("201" in str(respdata)):
#successful
return True
else:
#not successful
return False
return()
def changeIdentityName(self,thename,newname):
#changes name of identity, returns True if successful, False if not
requeststring="http://"+self.host+":" \
+self.port+"/identity/name/"+thename
datadict={"newname": newname}
dataparams=json.dumps(datadict)
respdata=requests.put(requeststring,data=dataparams)
if("204" in str(respdata)):
#successful
return True
else:
return False
def deleteIdentity(self,thename):
#deletes Identity, returns True if successful, false if not
requeststring="http://"+self.host+":" \
+self.port+"/identity/name/"+thename
respdata=requests.delete(requeststring)
if("204" in str(respdata)):
#successful
return True
else:
return False
# Namestore Section
def setNamestoreIdentity(self,thename):
#sets the default Identity for subsystem 'namestore'
#returns True if successful False if not
requeststring="http://"+self.host+":" \
+self.port+"/identity/subsystem/"+thename
datadict={"subsystem": "namestore"}
dataparams=json.dumps(datadict)
respdata=requests.put(requeststring,data=dataparams)
if("204" in str(respdata)):
return True
else:
return False
def getNamestoreEntries(self,thezone):
#returns a list of all namestore entries
requeststring="http://"+self.host+":" \
+self.port+"/namestore/"+thezone
respdata=requests.get(requeststring).json()
val=json.loads(json.dumps(respdata))
return(val)
#return(respdata)
def addNamestoreEntry(self,thezone,thename,thevalue,thetype):
#adds a namestore entry, returns true if successful, false if not
requeststring="http://"+self.host+":" \
+self.port+"/namestore/"+thezone
dataparams="{\"data\": [{\"value\": \""+thevalue+"\", \"record_type\": \""+thetype+"\", \"expiration_time\":\"1d\", \"private\": false, \"relative_expiration\": false, \"supplemental\": false, \"shadow\": false}], \"record_name\": \""+thename+"\"}"
respdata=requests.post(requeststring,data=dataparams)
if("204" in str(respdata)):
return True
else:
return False
def changeNamestoreEntry(self,thezone,thename,thevalue,thetype):
#changes a namestore entry, returns true if successful, false if not
requeststring="http://"+self.host+":" \
+self.port+"/namestore/"+thezone
dataparams="{\"data\": [{\"value\": \""+thevalue+"\", \"record_type\": \""+thetype+"\", \"expiration_time\":\"1d\", \"private\": false, \"relative_expiration\": false, \"supplemental\": false, \"shadow\": false}], \"record_name\": \""+thename+"\"}"
respdata=requests.put(requeststring,data=dataparams)
if("204" in str(respdata)):
return True
else:
return False
def deleteNamestoreEntry(self,thezone,thename):
#deletes a namestore entry, returns true if successful, false if not
requeststring="http://"+self.host+":" \
+self.port+"/namestore/"+thezone+"/"+thename
respdata=requests.delete(requeststring)
if("204" in str(respdata)):
return True
else:
return False
#GNS section
def getGNSValuesOfName(self,thezone,thename):
#returns a list of values and record types with the same record name
requeststring="http://"+self.host+":" \
+self.port+"/gns/"+thename+"."+thezone
respdata=requests.get(requeststring).json()
val=json.loads(json.dumps(respdata))
return(val)
def getGNSValuesOfNameAndType(self,thezone,thename,thetype):
#returns a list of values of a certain name and record type
requeststring="http://"+self.host+":" \
+self.port+"/gns/"+thename+"."+thezone+"?record_type="+thetype
respdata=requests.get(requeststring).json()
val=json.loads(json.dumps(respdata))
return(val)

BIN
testdata/cat.jpg vendored

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

21
testdata/sm.txt vendored

@ -0,0 +1,21 @@
The 8 Id Really Rather You Didnts
1. Id really rather you didnt act like a sanctimonious, holier-than-thou ass when describing my Noodly Goodness. If some people dont believe in me, thats okay. Really, Im not that vain. Besides, this isnt about them so dont change the subject.
2. Id really rather you didnt use my existence as a means to oppress, subjugate, punish, eviscerate, and/or, you know, be mean to others. I dont require sacrifices and purity is for drinking water, not people.
3. Id really rather you didnt judge people for the way they look, or how they dress, or the way they talk, or, well, just play nice, okay? Oh, and get this in your thick heads: woman = person. Man = person. Samey-samey. One is not better than the other, unless were talking about fashion and Im sorry, but I gave that to women and some guys who know the difference between teal and fuchsia.
4. Id really rather you didnt indulge in conduct that offends yourself, or your willing, consenting partner of legal age and mental maturity. As for anyone who might object, I think the expression is go f*** yourself, unless they find that offensive in which case they can turn off the TV for once and go for a walk for a change.
5. Id really rather you didnt challenge the bigoted, misogynist, hateful ideas of others on an empty stomach. Eat, then go after the b******.
6. Id really rather you didnt build multimillion-dollar churches / temples / mosques / shrines to my Noodly Goodness when the money could be better spent (take your pick):
a. Ending poverty
b. Curing diseases
c. Living in peace, loving with passion, and lowering the cost of cable
I might be a complex-carbohydrate omniscient being, but I enjoy the simple things in life. I ought to know. I am the creator.
7. Id really rather you didnt go around telling people I talk to you. Youre not that interesting. Get over yourself. And I told you to love your fellow man, cant you take a hint?
8. Id really rather you didnt do unto others as you would have them do unto you if you are into, um, stuff that uses a lot of leather / lubricant / lass Vegas. If the other person is into it, however (pursuant to #4), then have at it, take pictures, and for the love of mike, wear a condom! Honestly, its a piece of rubber. If I didnt want it to feel good when you did it I would have added spikes, or something.
Loading…
Cancel
Save