lastest changes
This commit is contained in:
0
client/client.go → client/go/client.go
Executable file → Normal file
0
client/client.go → client/go/client.go
Executable file → Normal file
34
client/go/mDNS.go
Normal file
34
client/go/mDNS.go
Normal 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
14
client/list-servers.go
Executable file → Normal 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))
|
||||
}
|
||||
BIN
client/python/__pycache__/ipfs_config.cpython-38.pyc
Normal file
BIN
client/python/__pycache__/ipfs_config.cpython-38.pyc
Normal file
Binary file not shown.
8
client/python/ipfs_config.py
Normal file
8
client/python/ipfs_config.py
Normal 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
|
||||
18
client/python/list-server.py
Normal file
18
client/python/list-server.py
Normal 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()
|
||||
Reference in New Issue
Block a user