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
1eb29b8c
Commit
1eb29b8c
authored
3 years ago
by
jeremy.martinot
Browse files
Options
Downloads
Patches
Plain Diff
Message have a Contenu in place of simple key, add right adress for a content ;)
parent
b5ff987b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/server.go
+20
-19
20 additions, 19 deletions
server/server.go
with
20 additions
and
19 deletions
server/server.go
+
20
−
19
View file @
1eb29b8c
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
type
Message
struct
{
type
Message
struct
{
Id
uint64
Id
uint64
Key
int
Content
Contenu
Type_
string
Type_
string
}
}
...
@@ -32,7 +32,7 @@ type Contenu struct {
...
@@ -32,7 +32,7 @@ type Contenu struct {
var
(
var
(
thisnode
Node
thisnode
Node
port
string
port
string
//Liste des requetes deja vues/effectués
Pourquoi int ?
//Liste des requetes deja vues/effectués
requests
[]
uint64
requests
[]
uint64
msg_count_uuid
uint64
//valeur dont on commencera a compter les id
msg_count_uuid
uint64
//valeur dont on commencera a compter les id
)
)
...
@@ -40,20 +40,22 @@ var (
...
@@ -40,20 +40,22 @@ var (
func
fillContents
()
{
func
fillContents
()
{
println
(
thisnode
.
MyKey
)
println
(
thisnode
.
MyKey
)
for
_
,
key
:=
range
thisnode
.
MyKey
{
for
_
,
key
:=
range
thisnode
.
MyKey
{
addContent
(
key
,
thisnode
.
Address
)
myContent
:=
createContenu
(
key
,
thisnode
.
Address
)
addContent
(
myContent
)
fmt
.
Println
(
key
)
fmt
.
Println
(
key
)
}
}
for
_
,
neighbour
:=
range
thisnode
.
Neighbours
{
for
_
,
neighbour
:=
range
thisnode
.
Neighbours
{
for
_
,
content
:=
range
neighbour
.
MyKey
{
for
_
,
key
:=
range
neighbour
.
MyKey
{
addContent
(
content
,
neighbour
.
Address
)
hisContent
:=
createContenu
(
key
,
neighbour
.
Address
)
addContent
(
hisContent
)
}
}
}
}
}
}
func
createMessage
(
id
uint64
,
key
int
,
_type
string
)
Message
{
func
createMessage
(
id
uint64
,
content
Contenu
,
_type
string
)
Message
{
return
Message
{
return
Message
{
Id
:
id
,
Id
:
id
,
Key
:
key
,
Content
:
content
,
Type_
:
_type
,
Type_
:
_type
,
}
}
}
}
...
@@ -136,17 +138,18 @@ func handleRequest(msg Message, conn net.Conn) {
...
@@ -136,17 +138,18 @@ func handleRequest(msg Message, conn net.Conn) {
sender
:=
conn
.
RemoteAddr
()
.
String
()
sender
:=
conn
.
RemoteAddr
()
.
String
()
requests
=
append
(
requests
,
msg
.
Id
)
requests
=
append
(
requests
,
msg
.
Id
)
if
!
hasAlreadySeen
(
msg
)
{
if
!
hasAlreadySeen
(
msg
)
{
if
hasKey
(
msg
.
Key
)
{
if
hasKey
(
msg
.
Content
.
Key
)
{
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Key
,
"POSITIVE"
),
sender
)
msg
.
Content
.
Origin
=
thisnode
.
Address
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Content
,
"POSITIVE"
),
sender
)
}
else
{
}
else
{
if
sendToClosestWhilePositive
(
msg
,
sender
)
==
true
{
if
sendToClosestWhilePositive
(
msg
,
sender
)
==
true
{
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Key
,
"POSITIVE"
),
sender
)
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Content
,
"POSITIVE"
),
sender
)
}
else
{
}
else
{
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Key
,
"NEGATIVE"
),
sender
)
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Content
,
"NEGATIVE"
),
sender
)
}
}
}
}
}
else
{
}
else
{
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Key
,
"NEGATIVE"
),
sender
)
sendMessage
(
createMessage
(
msg
.
Id
,
msg
.
Content
,
"NEGATIVE"
),
sender
)
}
}
}
}
...
@@ -155,12 +158,10 @@ func sortContents() {
...
@@ -155,12 +158,10 @@ func sortContents() {
return
thisnode
.
Contents
[
p
]
.
Key
<
thisnode
.
Contents
[
q
]
.
Key
})
return
thisnode
.
Contents
[
p
]
.
Key
<
thisnode
.
Contents
[
q
]
.
Key
})
}
}
func
addContent
(
key
int
,
ownerIp
string
)
{
func
addContent
(
content
Contenu
)
{
newcontent
:=
createContenu
(
key
,
ownerIp
)
thisnode
.
Contents
=
append
(
thisnode
.
Contents
,
content
)
thisnode
.
Contents
=
append
(
thisnode
.
Contents
,
newcontent
)
}
}
func
hasKey
(
key
int
)
bool
{
func
hasKey
(
key
int
)
bool
{
for
_
,
element
:=
range
thisnode
.
Contents
{
for
_
,
element
:=
range
thisnode
.
Contents
{
if
key
==
element
.
Key
{
if
key
==
element
.
Key
{
...
@@ -170,10 +171,9 @@ func hasKey(key int) bool {
...
@@ -170,10 +171,9 @@ func hasKey(key int) bool {
return
false
return
false
}
}
func
handleReply
(
msg
Message
,
src
string
)
bool
{
func
handleReply
(
msg
Message
,
src
string
)
bool
{
if
msg
.
Type_
==
"POSITIVE"
{
if
msg
.
Type_
==
"POSITIVE"
{
addContent
(
msg
.
Key
,
src
)
addContent
(
msg
.
Content
)
return
true
return
true
}
}
if
msg
.
Type_
==
"NEGATIVE"
{
if
msg
.
Type_
==
"NEGATIVE"
{
...
@@ -227,7 +227,8 @@ func main() {
...
@@ -227,7 +227,8 @@ func main() {
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
os
.
Exit
(
2
)
os
.
Exit
(
2
)
}
}
msg
:=
createMessage
(
msg_count_uuid
,
key
,
"REQUEST"
)
contentToFind
:=
createContenu
(
key
,
""
)
msg
:=
createMessage
(
msg_count_uuid
,
contentToFind
,
"REQUEST"
)
has
:=
sendToClosestWhilePositive
(
msg
,
thisnode
.
Address
)
has
:=
sendToClosestWhilePositive
(
msg
,
thisnode
.
Address
)
println
(
has
)
println
(
has
)
...
...
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