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
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os"
"strconv"
......@@ -14,6 +15,9 @@ import (
var arrFile []string
var idServ string
var port string
var parent int
var msgId = 0
var err error
// album represents data about a record album.
type album struct {
......@@ -32,22 +36,52 @@ var albums = []album{
{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++ {
if albums[i].ID == idServ {
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] {
resp, err := http.Get("http://localhost:808" + strconv.Itoa(albums[i].Neighb[j]) + "/req/" + idServ + "/" + c.Param("tlv") + "/" + strconv.Itoa(msgId))
printErr(err)
fmt.Println(resp.Status)
}
}
}
//c.IndentedJSON(http.StatusOK, albums)
}
}
func receiveReq(c *gin.Context) {
fmt.Println(c.Param("parent"))
fmt.Println(c.Param("tlv"))
idMsgInt, err := strconv.Atoi(c.Param("msgId"))
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)
}
......@@ -71,8 +105,8 @@ func main() {
port = strconv.Itoa(8080 + nbIdServ)
router := gin.Default()
router.GET("/req", reqNeighb)
router.GET("/req/:parent/:tlv", receiveReq)
router.GET("/initReq/:tlv", initReq)
router.GET("/req/:parent/:tlv/:msgId", receiveReq)
fmt.Println(port)
/*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment