Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SysDistribueTPGnutella
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ivan.rigo
SysDistribueTPGnutella
Commits
e376b791
Commit
e376b791
authored
2 years ago
by
ivan.rigo
Browse files
Options
Downloads
Patches
Plain Diff
Further test for Rnd/TLV needed
parent
a30c4db6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
web-service-gin/main.go
+43
-9
43 additions, 9 deletions
web-service-gin/main.go
with
43 additions
and
9 deletions
web-service-gin/main.go
+
43
−
9
View file @
e376b791
...
@@ -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
)
/*
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment