Skip to content
Snippets Groups Projects
Commit e376b791 authored by ivan.rigo's avatar ivan.rigo
Browse files

Further test for Rnd/TLV needed

parent a30c4db6
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"math/rand"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
...@@ -14,6 +15,9 @@ import ( ...@@ -14,6 +15,9 @@ import (
var arrFile []string var arrFile []string
var idServ string var idServ string
var port string var port string
var parent int
var msgId = 0
var err error
// album represents data about a record album. // album represents data about a record album.
type album struct { type album struct {
...@@ -32,22 +36,52 @@ var albums = []album{ ...@@ -32,22 +36,52 @@ var albums = []album{
{ID: "7", Neighb: []int{3, 4}}, {ID: "7", Neighb: []int{3, 4}},
} }
func reqNeighb(c *gin.Context) { func initReq(c *gin.Context) {
msgId = rand.Intn(100)
parent, err = strconv.Atoi(idServ)
printErr(err)
for i := 0; i < len(albums); i++ { for i := 0; i < len(albums); i++ {
if albums[i].ID == idServ { if albums[i].ID == idServ {
for j := 0; j < len(albums[i].Neighb); j++ { for j := 0; j < len(albums[i].Neighb); j++ {
resp, err := http.Get("http://localhost:808" + strconv.Itoa(albums[i].Neighb[j]) + "/req/" + idServ + "/" + strconv.Itoa(j)) if parent != albums[i].Neighb[j] {
printErr(err) resp, err := http.Get("http://localhost:808" + strconv.Itoa(albums[i].Neighb[j]) + "/req/" + idServ + "/" + c.Param("tlv") + "/" + strconv.Itoa(msgId))
fmt.Println(resp.Status) printErr(err)
fmt.Println(resp.Status)
}
} }
} }
} }
//c.IndentedJSON(http.StatusOK, albums)
} }
func receiveReq(c *gin.Context) { func receiveReq(c *gin.Context) {
fmt.Println(c.Param("parent")) idMsgInt, err := strconv.Atoi(c.Param("msgId"))
fmt.Println(c.Param("tlv")) printErr(err)
transmitterId, err := strconv.Atoi(c.Param("parent"))
printErr(err)
tlv, err := strconv.Atoi(c.Param("tlv"))
if msgId != idMsgInt {
msgId = idMsgInt
parent = transmitterId
fmt.Println("My parent is " + strconv.Itoa(transmitterId) + " and this is a message from the broadcast called " + strconv.Itoa(idMsgInt))
} else {
fmt.Println("I already have a parent,dont care")
}
tlv = tlv - 1
if tlv != 0 {
for i := 0; i < len(albums); i++ {
if albums[i].ID == idServ {
for j := 0; j < len(albums[i].Neighb); j++ {
if transmitterId != albums[i].Neighb[j] {
resp, err := http.Get("http://localhost:808" + strconv.Itoa(albums[i].Neighb[j]) + "/req/" + idServ + "/" + strconv.Itoa(tlv) + "/" + strconv.Itoa(msgId))
printErr(err)
fmt.Println(resp.Status)
}
}
}
}
} else {
fmt.Println("Witnessed end of broadcast")
}
c.Status(http.StatusOK) c.Status(http.StatusOK)
} }
...@@ -71,8 +105,8 @@ func main() { ...@@ -71,8 +105,8 @@ func main() {
port = strconv.Itoa(8080 + nbIdServ) port = strconv.Itoa(8080 + nbIdServ)
router := gin.Default() router := gin.Default()
router.GET("/req", reqNeighb) router.GET("/initReq/:tlv", initReq)
router.GET("/req/:parent/:tlv", receiveReq) router.GET("/req/:parent/:tlv/:msgId", receiveReq)
fmt.Println(port) fmt.Println(port)
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment