Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP2_Freenet_Go_Socket
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
Show more breadcrumbs
jeremy.martinot
TP2_Freenet_Go_Socket
Commits
64bea5f3
Commit
64bea5f3
authored
3 years ago
by
julian.ruhl
Browse files
Options
Downloads
Patches
Plain Diff
Unknown
parent
3a52b43b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+4
-2
4 additions, 2 deletions
README.md
server/deploy.py
+4
-0
4 additions, 0 deletions
server/deploy.py
server/server.go
+67
-25
67 additions, 25 deletions
server/server.go
with
75 additions
and
27 deletions
README.md
+
4
−
2
View file @
64bea5f3
# TP2
_
Freenet
_
Go
_
Socket
# TP2
Freenet
Go
Socket
Our amazing project !
\ No newline at end of file
Groupe: MARTINOTY, Jérémy; RÜHL, Julian
#
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server/deploy.py
+
4
−
0
View file @
64bea5f3
...
...
@@ -59,7 +59,11 @@ for i in range(6):
nodes
.
append
(
new_instance
)
print
(
"
Instance :
"
+
instance_name
+
"
created !
"
)
<<<<<<<
Updated
upstream
print
(
"
Waiting 60 seconds for cloud-init completion...
"
)
=======
print
(
"
Waiting 60 seconds for cloud-init completion...
"
);
>>>>>>>
Stashed
changes
sleep
(
60
)
for
instance
in
nodes
:
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
67
−
25
View file @
64bea5f3
...
...
@@ -15,6 +15,7 @@ import (
type
Message
struct
{
Id
int
Key
int
Ttl
int
Type_
string
}
...
...
@@ -36,15 +37,16 @@ var (
requests
[]
Message
)
func
createMessage
(
id
int
,
key
int
,
_type
string
)
Message
{
func
createMessage
(
id
int
,
key
int
,
ttl
int
,
_type
string
)
Message
{
return
Message
{
Id
:
id
,
Key
:
key
,
Ttl
:
ttl
,
Type_
:
_type
,
}
}
func
createContenu
(
key
int
,
origin
string
)
{
func
createContenu
(
key
int
,
origin
string
)
Contenu
{
return
Contenu
{
Key
:
key
,
Origin
:
origin
,
...
...
@@ -52,11 +54,24 @@ func createContenu(key int, origin string) {
}
func
fillContents
()
{
rands
:=
[
10
]
int
var
rands
=
[
10
]
int
{}
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
for
i
:=
0
;
i
<
len
(
rands
);
i
++
{
rands
[
i
]
=
rand
.
Intn
(
100
)
contents
=
append
(
contents
,
createContenu
(
v
[
i
],
node
.
Address
))
contents
=
append
(
contents
,
createContenu
(
rands
[
i
],
thisnode
.
Address
))
}
if
thisnode
.
Id
==
1
{
contents
[
3
]
=
createContenu
(
0xc0ffee
,
thisnode
.
Address
)
}
if
thisnode
.
Id
==
2
{
contents
[
2
]
=
createContenu
(
0xdead
,
thisnode
.
Address
)
}
if
thisnode
.
Id
==
3
{
contents
[
1
]
=
createContenu
(
0xbeef
,
thisnode
.
Address
)
}
}
...
...
@@ -113,39 +128,58 @@ func handleNewConn(conn net.Conn) {
fmt
.
Printf
(
"Received : %+v"
,
msg
)
if
msg
.
Type_
==
"REQUEST"
{
handleRequest
(
msg
,
conn
)
handleRequest
(
*
msg
,
conn
)
}
else
if
msg
.
Type_
==
"POSITIVE"
{
handlePositiveMessage
(
msg
,
conn
)
handlePositiveMessage
(
*
msg
,
conn
)
}
else
{
handleNegativeMessage
(
msg
,
conn
)
handleNegativeMessage
(
*
msg
,
conn
)
}
}
func
handleNegativeMessage
(
msg
Message
,
conn
net
.
Conn
)
{
}
func
handlePositiveMessage
(
msg
Message
,
conn
net
.
Conn
)
{
//transmettre message au noeud qui a démandé SAUF si nous étions le demandeur
}
func
getNode
(
id
int
)
Node
{
for
_
,
node
:=
range
thisnode
.
Neighbours
{
if
node
.
Id
==
id
{
return
node
}
}
return
thisnode
}
func
handleRequest
(
msg
Message
,
conn
net
.
Conn
)
{
new_ttl
:=
msg
.
Ttl
-
1
if
hasAlreadyRequested
(
msg
)
{
sendMessage
(
createMessage
(
thisnode
.
Id
,
msg
.
Key
,
new_ttl
,
"NEGATIVE"
),
getNode
(
msg
.
Id
))
}
else
{
requests
=
append
(
requests
,
msg
)
if
hasKey
(
msg
.
Key
)
{
sendMessage
(
createMessage
(
thisnode
.
Id
,
msg
.
Key
,
"POSITIVE"
))
sendMessage
(
createMessage
(
thisnode
.
Id
,
msg
.
Key
,
new_ttl
,
"POSITIVE"
)
,
getNode
(
msg
.
Id
)
)
}
else
{
//demander aux autres noeuds
sendMessageAllExcept
(
createMessage
(
thisnode
.
Id
,
msg
.
Key
,
new_ttl
,
"REQUEST"
),
getNode
(
msg
.
Id
))
}
}
}
func
hasKey
(
key
int
)
bool
{
for
_
,
element
:=
range
content
{
for
_
,
element
:=
range
content
s
{
if
key
==
element
.
Key
{
key_found
=
true
return
true
}
}
return
false
}
func
hasAlreadyRequested
(
newreq
Message
)
bool
{
for
_
,
request
:=
range
requests
{
if
request
.
Id
==
newreq
.
Id
&&
request
.
Key
==
newreq
.
Key
{
if
request
.
Key
==
newreq
.
Key
{
return
true
}
}
...
...
@@ -160,19 +194,27 @@ func main() {
thisnode
:=
readYaml
(
os
.
Args
[
2
])
port
:=
os
.
Args
[
1
]
fillContents
()
fmt
.
Println
(
"Starting server on "
+
thisnode
.
Address
+
":"
+
port
)
initial_node
:=
false
if
os
.
Args
[
3
]
==
"INIT"
{
initial_node
=
true
}
else
if
os
.
Args
[
3
]
!=
"WAIT"
{
fmt
.
Println
(
"Bad invocation. Require INIT or WAIT!"
)
os
.
Exit
(
0
)
}
fillContents
()
fmt
.
Println
(
"Starting server on "
+
thisnode
.
Address
+
":"
+
port
)
listenSocket
,
err
:=
net
.
Listen
(
"tcp"
,
thisnode
.
Address
+
":"
+
port
)
checkError
(
err
)
defer
listenSocket
.
Close
()
if
initial_node
{
sendMessage
(
createMessage
(
thisnode
.
Id
,
0xc0ffee
,
3
,
"REQUEST"
),
thisnode
.
Neighbours
[
0
])
}
for
{
connection
,
err
:=
listenSocket
.
Accept
()
...
...
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