commited readiptable
Signed-off-by: Akilan1999 <akilan.selvacoumar@planetscale.com>
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/p2p-rendering-computation.iml" filepath="$PROJECT_DIR$/.idea/p2p-rendering-computation.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/p2p-rendering-computation.iml
generated
Normal file
8
.idea/p2p-rendering-computation.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,8 +1,8 @@
|
||||
'''
|
||||
This scrypt creates basic config for IPFS server
|
||||
This scrypt creates basic config for IPFS server
|
||||
'''
|
||||
import ipfsApi
|
||||
|
||||
def config():
|
||||
api = ipfsApi.Client('127.0.0.1', 5001)
|
||||
return api
|
||||
return api
|
||||
|
||||
0
docs/About
Normal file
0
docs/About
Normal file
1
go.mod
1
go.mod
@@ -24,6 +24,7 @@ require (
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||
github.com/shirou/gopsutil v3.20.12+incompatible
|
||||
github.com/showwin/speedtest-go v1.1.1
|
||||
github.com/sirupsen/logrus v1.7.0 // indirect
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 // indirect
|
||||
|
||||
7
go.sum
7
go.sum
@@ -6,6 +6,8 @@ github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/
|
||||
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
@@ -116,6 +118,8 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M=
|
||||
github.com/shirou/gopsutil v3.20.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/showwin/speedtest-go v1.1.1 h1:anVwVssgk9MsN/ev8hXBcfMHAfu7o+6fUPvOYTQYkq8=
|
||||
github.com/showwin/speedtest-go v1.1.1/go.mod h1:Evr4so/j097J4zgdEyYvaBhzyKMgrTNUOwFQcXqUUzc=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
@@ -171,6 +175,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -227,6 +233,7 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -9,4 +9,5 @@ P2P module
|
||||
- Connect to reliable connection (that has some knowledge)
|
||||
- Check if the connection is still open (If not instruct the server to remove from table)
|
||||
- According speed tests
|
||||
- Send list of servers connection open
|
||||
- Send list of servers connection open
|
||||
- default 100 MB (to store tables of ip records)
|
||||
|
||||
10
p2p/ip_table.json
Normal file
10
p2p/ip_table.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ip_address":[
|
||||
{
|
||||
"ipv4":"23.23.232.2",
|
||||
"latency":3,
|
||||
"download": 34,
|
||||
"upload": 50
|
||||
}
|
||||
]
|
||||
}
|
||||
44
p2p/readiptable.go
Normal file
44
p2p/readiptable.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Get IP table Data
|
||||
|
||||
type IpAddresses struct {
|
||||
IpAddress []IpAddress `json:"ip_address"`
|
||||
}
|
||||
|
||||
type IpAddress struct {
|
||||
Ipv4 string `json:"ipv4"`
|
||||
Latency float32 `json:"latency"`
|
||||
Download float32 `json:"download"`
|
||||
Upload float32 `json:"upload"`
|
||||
}
|
||||
|
||||
func ReadIpTable()(*IpAddresses ,error){
|
||||
|
||||
jsonFile, err := os.Open("ip_table.json")
|
||||
// if we os.Open returns an error then handle it
|
||||
if err != nil {
|
||||
return nil,err
|
||||
}
|
||||
|
||||
// defer the closing of our jsonFile so that we can parse it later on
|
||||
defer jsonFile.Close()
|
||||
|
||||
// read our opened xmlFile as a byte array.
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
// we initialize our Users array
|
||||
var ipAddresses IpAddresses
|
||||
|
||||
// we unmarshal our byteArray which contains our
|
||||
// jsonFile's content into 'users' which we defined above
|
||||
json.Unmarshal(byteValue, &ipAddresses)
|
||||
|
||||
return &ipAddresses, nil
|
||||
}
|
||||
12
p2p/readiptable_test.go
Normal file
12
p2p/readiptable_test.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadIpTable(t *testing.T) {
|
||||
_, err := ReadIpTable()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
71
p2p/speedtest/speedtest.go
Normal file
71
p2p/speedtest/speedtest.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/showwin/speedtest-go/speedtest"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
URL string `xml:"url,attr"`
|
||||
Lat string `xml:"lat,attr"`
|
||||
Lon string `xml:"lon,attr"`
|
||||
Name string `xml:"name,attr"`
|
||||
Country string `xml:"country,attr"`
|
||||
Sponsor string `xml:"sponsor,attr"`
|
||||
ID string `xml:"id,attr"`
|
||||
URL2 string `xml:"url2,attr"`
|
||||
Host string `xml:"host,attr"`
|
||||
Distance float64
|
||||
Latency time.Duration
|
||||
DLSpeed float64
|
||||
ULSpeed float64
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
SpeedTest()
|
||||
}
|
||||
|
||||
func SpeedTest() {
|
||||
user, _ := speedtest.FetchUserInfo()
|
||||
|
||||
serverList, _ := speedtest.FetchServerList(user)
|
||||
targets, _ := serverList.FindServer([]int{})
|
||||
|
||||
for _, s := range targets {
|
||||
fmt.Print(strings.Split(s.URL, "/upload")[0] + "/latency.txt")
|
||||
s.PingTest()
|
||||
s.DownloadTest(false)
|
||||
s.UploadTest(false)
|
||||
|
||||
fmt.Printf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed)
|
||||
}
|
||||
}
|
||||
|
||||
// PingTest executes test to measure latency
|
||||
// Function modified for custom URl
|
||||
func (s *Server) PingTest() error {
|
||||
pingURL := strings.Split(s.URL, "/upload")[0] + "/latency.txt"
|
||||
fmt.Print(pingURL)
|
||||
|
||||
l := time.Duration(100000000000) // 10sec
|
||||
for i := 0; i < 3; i++ {
|
||||
sTime := time.Now()
|
||||
resp, err := http.Get(pingURL)
|
||||
fTime := time.Now()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fTime.Sub(sTime) < l {
|
||||
l = fTime.Sub(sTime)
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
s.Latency = time.Duration(int64(l.Nanoseconds() / 2))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
//"fmt"
|
||||
)
|
||||
@@ -14,6 +16,19 @@ func Server() {
|
||||
c.JSON(http.StatusOK, ServerInfo())
|
||||
})
|
||||
|
||||
// Route build to do a speed test
|
||||
r.GET("/upload", func(c *gin.Context) {
|
||||
file, _ := c.FormFile("file")
|
||||
log.Println(file.Filename)
|
||||
|
||||
// Upload the file to specific dst.
|
||||
// c.SaveUploadedFile(file, dst)
|
||||
|
||||
c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
|
||||
})
|
||||
|
||||
|
||||
|
||||
/*r.GET("/create_vm/:virtualization", func(c *gin.Context) {
|
||||
virtualization := c.Param("virtualization")
|
||||
// Runs based on Preallocated VM size
|
||||
|
||||
38
server/upload_file.go
Normal file
38
server/upload_file.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid" // To generate random file names
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func saveFileHandler(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
|
||||
// The file cannot be received.
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
|
||||
"message": "No file is received",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Retrieve file information
|
||||
extension := filepath.Ext(file.Filename)
|
||||
// Generate random file name for the new uploaded file so it doesn't override the old file with same name
|
||||
newFileName := uuid.New().String() + extension
|
||||
|
||||
// The file is received, so let's save it
|
||||
if err := c.SaveUploadedFile(file, "/tmp/" + newFileName); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "Unable to save the file",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// File saved successfully. Return proper result
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "Your file has been successfully uploaded.",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user