lastest changes

This commit is contained in:
2021-01-20 13:05:04 +04:00
parent a71905d698
commit 16fb7ca42f
20 changed files with 152 additions and 1 deletions

0
client/client.go → client/go/client.go Executable file → Normal file
View File

34
client/go/mDNS.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import (
"github.com/grandcat/zeroconf"
"log"
"context"
"time"
)
func main() {
// Discover all services on the network (e.g. _workstation._tcp)
resolver, err := zeroconf.NewResolver(nil)
if err != nil {
log.Fatalln("Failed to initialize resolver:", err.Error())
}
entries := make(chan *zeroconf.ServiceEntry)
go func(results <-chan *zeroconf.ServiceEntry) {
for entry := range results {
log.Println(entry)
}
log.Println("No more entries.")
}(entries)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
err = resolver.Browse(ctx, "_workstation._tcp", "local.", entries)
if err != nil {
log.Fatalln("Failed to browse:", err.Error())
}
<-ctx.Done()
}

14
client/list-servers.go Executable file → Normal file
View File

@@ -11,6 +11,7 @@ import (
"github.com/christophwitzko/go-curl"
"net/http"
"encoding/json"
"reflect"
)
func list_servers() (error, []byte){
@@ -43,8 +44,21 @@ func list_servers() (error, []byte){
return nil ,data
}
func main() {
// Where your local node is running on localhost:5001
_ , data := list_servers()
m := map[string]interface{}{}
// print type of output
fmt.Println(reflect.TypeOf(data))
// print
// Debug output
/*for _, element := range data {
fmt.Println(string(element))
}*/
//fmt.Println(string(data))
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
'''
This scrypt creates basic config for IPFS server
'''
import ipfsApi
def config():
api = ipfsApi.Client('127.0.0.1', 5001)
return api

View File

@@ -0,0 +1,18 @@
'''
This scrypt uses curl to list servers in the IPFS network
'''
import requests
import json
def list_servers():
peers = requests.post('http://127.0.0.1:5001/api/v0/swarm/peers')
# TODO: Detect nodes that are servers
peers_dict = peers.json()
# Ping for each node
for i in peers_dict['Peers']:
ping = requests.post('http://127.0.0.1:5001/api/v0/ping?arg='+i['Peer']+'&count=1')
# Create a replace function TODO
print(str(ping.content)[2:-3])
list_servers()