| Current Path : /var/www/html/venkat/ |
| Current File : //var/www/html/venkat/threed.go |
package main
import (
"fmt"
"time"
"math/rand"
)
//Total 100 Nodes - Choose the number of nodes for each cagetory.
const n = 100 //n - number of nodes
const sn = 2 // sy - no of sybil nodes
const dn = 4 // sy - no of disguised nodes
const mn = 4 // sy - no of malicious nodes
const mnei = 4 // nei - minimum neighbors
//const fnei = 2 // fnei - additional neighbours while processing
const session = 2 // session - number of rounds the experiment has to be done
const def = 1 // def - duplicate entry in fact table by a node; 0 - no duplicate and 1 - duplicate
const threshold = 0.5 // threshold you want to set for acceptance of score
const nos = 4 // Number of session you want to run
const nra = 1 // nra - node response considered for accepting the message; 0 - no response permitted, 1- permitted
//Assign values of each table attributes
const sta = 1 //sta - no. of service table attributes
const na = 12 //na - node (main table) attribute
const mi = 6 //mi - node message services or number of message services
const nsa = 5 //nsa - node service attribute
//const nsv = 2 //nsv - node service value; for example, if message service or id (mi) is traffic then nsv 0 refers no traffic; 1 refers traffic; 2 may refer too much traffic,..
const fa = 6 //fa - fact attribute
const tsa = 2 //tsa - trust score attribute
const sca = 4 //sca - score computation attribute
const fec = 1//fec - maximum entry for a node allowed in fact table - 0 (no limit), 1(limit)
const fe = 2//fe - maximum entry for a node allowed in fact table
const ne = 2 //ne multiples of total nodes to find number of entries for each node in activity table
const fsize = 1000 // fsize - fact table size that is maximum entry allowed.
const vtype = 2 // vtype - number of vote type --> -1 - negative, 1 - positive, 0 - neutral and 2 or more are for incentive
const vvalue = 2 // vvalue - number of possible values for each vote --> consider 0,1,2...
//const sta = 2 // sta -number of service table attribute
const maxvote = 1 //maxvote - maximum number of vote for each type
const incentive = 1 //incentive - incentive allowed or not; 0 - no incentive, 1- incentive
//Declaration of the tables
const nsvarraysize = 7 // nsvarraysize - is that how many different values in nsv array
var nsv = []int {2,3,4,4,5,2,2} //nsv - node service value; for example, if message service or id (mi) is traffic then nsv 0 refers no traffic; 1 refers traffic; 2 may refer too much traffic,..
var nodemain[n][n*ne][na]int
var nodeservice[n][mi][nsa]int
var nodeservicetable[mi][sta]int
var nodeneighbor[n][n]int
var fact1 [fsize][fa]int
//var fact1 [n][fe][fa]int
var fact2 [n][fe][fa]int
var tscore [n][tsa]float64
var tcompute [n][n*n][sca]float64 // for keeping the vote values
var x [2][2][2]int
var presentsession int
// This function gives unique neighbors for the nodes
func uniqueRand(node int) {
for i := 0; i < mnei; i++ {
rand.Seed(time.Now().UnixNano())
nodeneighbor[node][i+1] = rand.Intn(n)
for j := 1; j < i+1 ; j++ {
if nodeneighbor[node][j] == nodeneighbor[node][i+1] {
i--;
break;
}
}
}
nodeneighbor[node][0] = mnei;
for i := mnei + 1; i < n; i++ {
nodeneighbor[node][i] = -1
}
}
//Initialize the node entry that is to ensure it is empty in the beginning by giving the expired as -1
func nodeinitialize() {
for i := 0; i < n; i++ {
for j := 0; j < n * ne ; j++ {
nodemain[i][j][1] = -1
}
}
}
//Initial resource fixing for each device
// This function allot the resources for the nodes according to its behaviour
// nodeservice[][1][0] refers the service 1 is applicable or not; -1 not applicable, 0 or 1 or .. service values. At present it is only -1, and 1 that is available 1 not available -1
// nodeservice[][][1] refers malicious or genuine; 2 sybil, 1 disguise, 3 genuine and 0 malicious;
// nodeservice[][][2] refers status id; for example, 0 open, 1 not open;
// nodeservice[][][3] refers correct or incorrect service; for example, -1 incorrect service, 1 correct service;
// nodeservice[][][4] refers data ownership; from whom this data has come that is its own or sent by some one
func resource() {
fmt.Println("######### Node Service Allocation #########")
var eligible int
var svalue int
// rand.Seed(time.Now().UnixNano())
// genuinestatus := rand.Intn(nsv[])
for s:= 0; s < n; s++ {
if s < mn { //Malicious Nodes
//fmt.Println("Malicious Nodes---------------")
for i := 0; i < mi; i++ {
rand.Seed(time.Now().UnixNano())
eligible = rand.Intn(2)
if eligible == 1 {
for j := 0; j < 1000; j++ { //in 1000 attempt non-correct status value will be identified
rand.Seed(time.Now().UnixNano())
svalue = rand.Intn(nsv[i])
if svalue != nodeservicetable[i][0] {
nodeservice[s][i][0] = 1
nodeservice[s][i][1] = 0
nodeservice[s][i][2] = svalue
nodeservice[s][i][3] = -1
nodeservice[s][i][4] = s
break
}
}
} else {
nodeservice[s][i][0] = -1
nodeservice[s][i][1] = -1
}
}
} else if s >= mn && s < mn + dn { // Disguised Nodes
//fmt.Println("Disguised Nodes---------------")
for i := 0; i < mi; i++ {
rand.Seed(time.Now().UnixNano())
eligible = rand.Intn(2)
if eligible == 1 {
rand.Seed(time.Now().UnixNano())
disguisedecision := rand.Intn(2)
if disguisedecision == 1 {
nodeservice[s][i][0] = 1
nodeservice[s][i][1] = 1
nodeservice[s][i][2] = nodeservicetable[i][0]
nodeservice[s][i][3] = 1
nodeservice[s][i][4] = s
} else {
for j := 0; j < 1000; j++ { //in 1000 attempt non-correct status value will be identified
rand.Seed(time.Now().UnixNano())
svalue = rand.Intn(nsv[i])
if svalue != nodeservicetable[i][0] {
nodeservice[s][i][0] = 1
nodeservice[s][i][1] = 1
nodeservice[s][i][2] = svalue
nodeservice[s][i][3] = -1
nodeservice[s][i][4] = s
break
}
}
}
} else {
nodeservice[s][i][0] = -1
nodeservice[s][i][1] = -1
}
}
} else if s >= mn + dn && s < mn + dn + sn { // Sybil Nodes
//fmt.Println("Sybil Nodes ------------------")
for i := 0; i < mi; i++ {
rand.Seed(time.Now().UnixNano())
eligible = rand.Intn(2)
if eligible == 1 {
for j := 0; j < 1000; j++ { //in 1000 attempt non-correct status value will be identified
rand.Seed(time.Now().UnixNano())
svalue = rand.Intn(nsv[i])
if svalue != nodeservicetable[i][0] {
nodeservice[s][i][0] = 1
nodeservice[s][i][1] = 2
nodeservice[s][i][2] = svalue
nodeservice[s][i][3] = -1
nodeservice[s][i][4] = s
break
}
}
} else {
nodeservice[s][i][0] = -1
nodeservice[s][i][1] = -1
}
}
} else if s > mn + dn + sn {
//fmt.Println("Genuine Nodes ---------------")
for i := 0; i < mi; i++ {
rand.Seed(time.Now().UnixNano())
eligible = rand.Intn(2)
if eligible == 1 {
nodeservice[s][i][0] = 1
nodeservice[s][i][1] = 3
nodeservice[s][i][2] = nodeservicetable[i][0]
nodeservice[s][i][3] = 1
nodeservice[s][i][4] = s
} else {
nodeservice[s][i][0] = -1
nodeservice[s][i][1] = -1
}
}
}
fmt.Println(s,"--",nodeservice[s])
}
}
//function to update the resource
//nodetype - nodeservice[][1];type of node; 0 malcious, 1 disguise, 2, sybil and 3 for genuine
//nodetype - nodeservice[][0];applicable(1) or not(-1);
//nodeservice[][2] - service value
//nodeservice[][3] - correct or incorrect
//nodeservice[][4] - who is the owner of the data added
func updateresource(nodei int, nodesend int, serviceid int, servicevalue int, messagecorrect int, nodetype int) {
for i := 0; i < mi; i++ {
if nodeservice[nodei][serviceid][0] == -1 {
nodeservice[nodei][serviceid][0] = 1
nodeservice[nodei][serviceid][1] = nodetype
nodeservice[nodei][serviceid][2] = servicevalue
nodeservice[nodei][serviceid][3] = messagecorrect
nodeservice[nodei][serviceid][4] = nodesend
break
}
}
}
//Alloting the neighbours
func neighbourallot() {
fmt.Println("######## Node Neighbors Allocation ##########")
for i:= 0; i < n; i++ {
uniqueRand(i)
fmt.Println(i,"--",nodeneighbor[i])
}
}
//Intializing the fact table with -1
// array 0,
func factinitialize() {
for i := 0; i < fsize; i++ {
fact1[i][0] = -1
fact1[i][4] = -1
}
}
func autoserviceupdate() {
for i := 0; i < mi; i++ {
rand.Seed(time.Now().UnixNano())
status := rand.Intn(nsv[i])
nodeservicetable[i][0] = status
}
fmt.Println("done")
//resource() //update resource table of all nodes
}
//user can insert the additional attribute and equivalent computation here.
func factadditionalattri(nodei int, entryrow int, addattri int) {
k := 0
var addfactattribute[] int
for j := addattri; j < fa; j++ {
addfactattribute[k] = 0
k++
}
k = 0
for j := addattri; j < fa; j++ {
fact1[entryrow][j] = addfactattribute[k]
k++
}
}
//Node makes entry into the fact table
//array 0, node id | array 1, message id | array 2 genuine | array 3 present session | array 4 count
//array 5 message status
func factentry(nodei int) {
rand.Seed(time.Now().UnixNano())
messageid := rand.Intn(mi)
nomessage := 1
for j := 0; j < na; j++ {
if nodeservice[nodei][messageid][0] != -1 {
nomessage = 0
break;
}
rand.Seed(time.Now().UnixNano())
messageid = rand.Intn(mi)
}
if nodemain[nodei][messageid][7] == 0 {
rand.Seed(time.Now().UnixNano())
randstatus := rand.Intn(nsv[messageid])
for j := 0; j < 100; j++ {
if randstatus != nodeservicetable[messageid][0] {
nodeservice[nodei][messageid][2] = randstatus
break;
}
rand.Seed(time.Now().UnixNano())
messageid = rand.Intn(mi)
}
} else {
nodeservice[nodei][messageid][2] = nodeservicetable[messageid][0]
}
if nomessage == 0 {
for i := 0; i < fe; i++ {
if fact1[i][0] == messageid && def == 0 {
//fact1[i][1] = nodeservice[nodei][messageid][0]
fact1[i][1] = messageid
fact1[i][2] = nodeservice[nodei][messageid][1] //node genuine or malicious
fact1[i][5] = nodeservice[nodei][messageid][2]
fact1[i][3] = fact1[i][3] + 1
factadditionalattri(nodei, i, 4)
} else if fact1[i][0] == -1 {
count := 0
if fec == 1 {
for k := 0; k < fe; k++ {
if fact1[k][0] == nodei {
count++
}
}
}
if count >= fe {
break;
}
fact1[i][0] = nodei
fact1[i][1] = messageid
fact1[i][2] = nodeservice[nodei][messageid][1]
fact1[i][5] = nodeservice[nodei][messageid][2]
fact1[i][3] = presentsession
fact1[i][4] = fact1[i][4] + 1
factadditionalattri(nodei, i, 6)
if incentive == 1 {
nodeincentivepost(nodei, 1)
}
}
}
}
}
func neighborcheck(nodei int, neighborid int) bool{
for i := 1; i <n ; i++ {
if nodeneighbor[nodei][i] == neighborid {
return true
} else if nodeneighbor[nodei][i] == -1 {
break
}
}
return false
}
// Initialize the trust compute table. Maximum number of votes allowed for each node is
// total node * total node
func nodetrustinitialize() {
for i := 1; i < n; i++ {
for j := 1; j < n*n; j++ {
tcompute[i][j][0] = -1
tcompute[i][j][2] = -1
}
}
}
// Initialize the trust compute table. Maximum number of votes allowed for each node is
// total node * total node
func nodemaininitialize() {
for i := 1; i < n; i++ {
for j := 1; i < n*ne; i++ {
nodemain[i][j][1] = -1
}
}
}
//initializing the score of the nodes
func scoreinitialize() {
for i := 1; i < n; i++ {
tscore[i][1] = tscore[i][0] // past session - for history
tscore[i][0] = 0 // present session
}
}
//tcompute array 0, votetype | array 1, votevalue | array 2, voter | array 3 present session
func nodevotepost(voter int, votee int, votetype int, votevalue int, messageid int) {
votecount := 0
for i := 1; i < n*n; i++ {
if tcompute[votee][i][2] == float64(voter) {
votecount++
}
if tcompute[votee][i][2] == float64(voter) {
votecount++
}
if tcompute[votee][i][0] == -1 && votecount < maxvote {
tcompute[votee][i][0] = float64(votetype)
tcompute[votee][i][1] = float64(votevalue)
tcompute[votee][i][2] = float64(voter)
tcompute[votee][i][3] = float64(presentsession)
tscore[votee][0] = tscore[votee][0] + float64(votevalue)
}
if votevalue == 0 {
output := factcompute(messageid)
if output == -1 {
tscore[votee][0] = -1
}
}
break
}
}
func nodeincentivepost(nodei int, incentivevalue int) {
incentivecount := 0
for i := 1; i < n*n; i++ {
if tcompute[nodei][i][0] == 2 {
incentivecount++
}
if tcompute[nodei][i][0] == -1 && incentivecount < incentive {
tcompute[nodei][i][0] = 2
tcompute[nodei][i][1] = float64(incentivevalue)
tcompute[nodei][i][2] = float64(nodei)
tcompute[nodei][i][3] = float64(presentsession)
tscore[nodei][0] = tscore[nodei][0] + float64(incentivevalue)
break
}
}
}
func noderesponseaction(nodei int) {
rand.Seed(time.Now().UnixNano())
entryid := rand.Intn(n*ne)
for i := 0; i < n*ne; i++ {
if (nodemain[nodei][entryid][10] == 2 || nodemain[nodei][entryid][0] == 2) && nodemain[nodei][entryid][1] != -1 && nodemain[nodei][entryid][4] != nodei {
break;
} else {
entryid = rand.Intn(n*ne)
}
}
accept := -1
negative := 0
output := 0
messageidentity := nodemain[nodei][entryid][5]
if nodeservice[nodei][messageidentity][0] != 1 {
if nodeservice[nodei][messageidentity][2] == nodemain[nodei][entryid][6] {
rand.Seed(time.Now().UnixNano())
voteoption := rand.Intn(2)
if voteoption == 1 {
nodevotepost(nodei, nodemain[nodei][entryid][4], 1, rand.Intn(vvalue), nodemain[nodei][entryid][5]) // positive vote --- range random to be checked
nodemain[nodei][entryid][9] = 1 //message accept (1)
}
}else {
nodevotepost(nodei, nodemain[nodei][entryid][4], 0, 0, nodemain[nodei][entryid][5]) //negative vote if the message present with the owner and received are conflicting
}
}
if tscore[nodei][0] > threshold && tscore[nodei][1] > 0{ //need to be updated according to the history
accept = 1
}
if accept == -1 {
output = factcompute(nodemain[nodei][entryid][5])
if output == 1 {
accept = 1
}else {
nodevotepost(nodei, nodemain[nodei][entryid][4], 0, 0, nodemain[nodei][entryid][5]) //negative vote
negative = 1
}
}
if accept == -1 && negative == 0 && nra == 1 {
output = responsecompute(nodei, nodemain[nodei][entryid][5])
if output == 1 {
accept = 1
}else {
nodevotepost(nodei, nodemain[nodei][entryid][4], 0, 0, nodemain[nodei][entryid][5]) //negative vote
negative = 1
}
}
nodemain[nodei][entryid][9] = accept
rand.Seed(time.Now().UnixNano())
voteoption := rand.Intn(2)
if voteoption == 1 && accept == 1{
nodevotepost(nodei, nodemain[nodei][entryid][4], 1, rand.Intn(vvalue), nodemain[nodei][entryid][5]) // positive vote --- range random to be checked
updateresource(nodei, nodemain[nodei][entryid][4], nodemain[nodei][entryid][5], nodemain[nodei][entryid][6], nodemain[nodei][entryid][11], nodemain[nodei][entryid][7]) // update the resource
} else if nodei > mn && nodei < dn + sn {
rand.Seed(time.Now().UnixNano())
voteoption := rand.Intn(2)
if voteoption == 1 {
nodevotepost(nodei, nodemain[nodei][entryid][4], 1, rand.Intn(vvalue), nodemain[nodei][entryid][5]) // positive vote -- range random function to be checked and added
updateresource(nodei, nodemain[nodei][entryid][4], nodemain[nodei][entryid][5], nodemain[nodei][entryid][6], nodemain[nodei][entryid][11], nodemain[nodei][entryid][7]) // update the resource
} else {
nodevotepost(nodei, nodemain[nodei][entryid][4], 0, 0, nodemain[nodei][entryid][5]) //negative vote
}
}else if nodei < mn {
nodevotepost(nodei, nodemain[nodei][entryid][4], 0, 0, nodemain[nodei][entryid][5]) //negative vote
}
}
//function to decide based on the node neighbors response majority
func responsecompute(nodei int, messageid int) int {
var responsecount[nsvarraysize] int
var status int
var total int
var responsescore float64
for i := 0; i < nsv[messageid]; i++ {
responsecount[i] = 0
}
for i := 0; i < n*ne; i++ {
if nodemain[nodei][i][5] == messageid && nodemain[nodei][i][0] == 2 && nodemain[nodei][i][9] != -1 && nodemain[nodei][i][1] != 1 {
status = nodemain[nodei][i][7]
responsecount[status] ++
total ++
}
}
if total > 0 {
responsescore = float64(responsecount[messageid]/total)
if responsescore > 0.5 {
return 1
} else if responsescore < 0.3 {
return -1
} else {
return 0
}
}
return 0
}
//function to check the fact majority
func factcompute(messageid int) int {
var fcount[nsvarraysize] int
var status int
var total int
var factscore float64
for i := 0; i < nsv[messageid]; i++ {
fcount[i] = 0
}
for i := 0; i < fsize; i++ {
if fact1[i][1] == messageid && fact1[i][3] == presentsession {
status = fact1[i][5]
fcount[status] ++
total ++
}
}
if total > 0 {
factscore = float64(fcount[messageid]/total)
if factscore > 0.5 {
return 1
} else if factscore < 0.3 {
return -1
} else {
return 0
}
}
return 0
}
// Node activity on the request of the neighbour node. 1 refers request and 2 refers response
// array 0, request(1)/response(2)| array 1, (-1) expired or (1) non-expired| array 2, owner id (received the request) | array 3, uniqueness entry id
// array 4, neighbor(sender of the request) identity | array 5, message identity | array 6, status identity | array 7 genuine/non-genuine/sybil/diguise
// array 8, session identity | array 9, accept(1) or reject(-1) or nodecision(0) | array 10, set response is given for the neighbor (that is 2)
// array 11, correct message(1) or incorrect message(-1).
func noderesponse(nodei int) {
rand.Seed(time.Now().UnixNano())
entryid := rand.Intn(n*ne)
for i := 0; i < n*ne; i++ {
if nodemain[nodei][entryid][0] == 1 && nodemain[nodei][entryid][1] != -1 {
break;
} else {
entryid = rand.Intn(n*ne)
}
}
uniqueentryid := nodemain[nodei][entryid][3]
neighborid := nodemain[nodei][entryid][4]
messageid := nodemain[nodei][entryid][5]
for i := 0; i < n*ne; i ++ {
if nodemain[neighborid][i][3] == uniqueentryid {
nodemain[neighborid][i][10] = 2 //set the response in the neighbour
nodemain[neighborid][i][6] = nodeservice[nodei][messageid][0]
nodemain[neighborid][i][7] = nodeservice[nodei][messageid][1]
nodemain[neighborid][i][11] = nodeservice[nodei][messageid][3]
nodemain[nodei][entryid][1] = -1
nodemain[nodei][entryid][9] = 1
}
}
if neighborcheck(nodei, neighborid) == false {
availableneighbor := nodeneighbor[nodei][0]
nodeneighbor[nodei][availableneighbor+1] = neighborid
nodeneighbor[nodei][0] = availableneighbor + 1
}
}
func sendmessage(nodei int) {
rand.Seed(time.Now().UnixNano())
neighborid := rand.Intn(nodeneighbor[nodei][0])
for i := 0; i < 100; i++ {
if neighborid == 0 {
neighborid = rand.Intn(nodeneighbor[nodei][0])
} else {
break
}
}
nentryid := 0 //finding neighbor free entry in the table
for i := 0; i < n * ne; i++ {
if nodemain[neighborid][i][1] == -1 {
nentryid = i;
break
}
}
oentryid := 0 //finding node's free entry in the table
for i := 0; i < n * ne; i++ {
if nodemain[neighborid][i][1] == -1 {
oentryid = i
}
}
rand.Seed(time.Now().UnixNano())
uniqueid := rand.Intn(1000000)
var messageid int
for i := 0; i < 100; i++ { //in 100 attempts it may find randomly available message identity
rand.Seed(time.Now().UnixNano())
messageid = rand.Intn(mi)
if nodeservice[nodei][messageid][0] != -1 {
break
}
}
nodemain[neighborid][nentryid][0] = 2
nodemain[neighborid][nentryid][1] = 1
nodemain[neighborid][nentryid][2] = neighborid
nodemain[neighborid][nentryid][3] = uniqueid
nodemain[neighborid][nentryid][4] = nodei
nodemain[neighborid][nentryid][5] = messageid
nodemain[neighborid][nentryid][6] = nodeservice[nodei][messageid][2]
nodemain[neighborid][nentryid][7] = nodeservice[nodei][messageid][1]
nodemain[neighborid][nentryid][8] = presentsession
nodemain[neighborid][nentryid][9] = 0
nodemain[neighborid][nentryid][10] = -1
nodemain[neighborid][nentryid][11] = nodeservice[nodei][messageid][3]
//array 2 is owner and array 4 is neighbor (target)
nodemain[nodei][oentryid][0] = 2
nodemain[nodei][oentryid][1] = 1
nodemain[nodei][oentryid][2] = neighborid
nodemain[nodei][oentryid][3] = uniqueid
nodemain[nodei][oentryid][4] = nodei
nodemain[nodei][oentryid][5] = messageid
nodemain[nodei][oentryid][6] = nodeservice[nodei][messageid][2]
nodemain[nodei][oentryid][7] = nodeservice[nodei][messageid][1]
nodemain[nodei][oentryid][8] = presentsession
nodemain[nodei][oentryid][9] = 0
nodemain[nodei][oentryid][10] = -1
nodemain[nodei][oentryid][11] = nodeservice[nodei][messageid][3]
}
//this function post the node request
//here array 4 is the owner identity and array 2 is the neighbor(target) identity
func noderequest(nodei int) {
rand.Seed(time.Now().UnixNano())
neighborid := rand.Intn(nodeneighbor[nodei][0])
for i := 0; i < 100; i++ {
if neighborid == 0 {
neighborid = rand.Intn(nodeneighbor[nodei][0])
} else {
break
}
}
nentryid := 0 //finding neighbor free entry in the table
for i := 0; i < n * ne; i++ {
if nodemain[neighborid][i][1] == -1 {
nentryid = i;
break
}
}
oentryid := 0 //finding node's free entry in the table
for i := 0; i < n * ne; i++ {
if nodemain[neighborid][i][1] == -1 {
oentryid = i
}
}
rand.Seed(time.Now().UnixNano())
uniqueid := rand.Intn(1000000)
rand.Seed(time.Now().UnixNano())
messageid := rand.Intn(mi)
nodemain[neighborid][nentryid][0] = 1
nodemain[neighborid][nentryid][1] = 1
nodemain[neighborid][nentryid][2] = neighborid
nodemain[neighborid][nentryid][3] = uniqueid
nodemain[neighborid][nentryid][4] = nodei
nodemain[neighborid][nentryid][5] = messageid
nodemain[neighborid][nentryid][8] = presentsession
nodemain[neighborid][nentryid][9] = 0
//array 2 is owner and array 4 is neighbor (target)
nodemain[nodei][oentryid][0] = 1
nodemain[nodei][oentryid][1] = 1
nodemain[nodei][oentryid][2] = nodei
nodemain[nodei][oentryid][3] = uniqueid
nodemain[nodei][oentryid][4] = neighborid
nodemain[nodei][oentryid][5] = messageid
nodemain[nodei][oentryid][8] = presentsession
nodemain[nodei][oentryid][9] = 0
}
//this reinializes the entry for the next session
func reinitialize() {
scoreinitialize()
factinitialize()
nodetrustinitialize()
nodemaininitialize()
presentsession++
}
//Main function for a node to start the process.
func nodeactivity(nodei int) {
j := 1
for j = 1; j < nos; j++ {
i := 1
for i = 1; i < 100; i++ {
rand.Seed(time.Now().UnixNano())
decideactivity := rand.Intn(5)
//factentry(nodei)
//noderequest(nodei)
if decideactivity == 0 {
factentry(nodei)
//fmt.Println("Fact-",nodei)
} else if decideactivity == 1 {
noderequest(nodei)
//fmt.Println("request",nodei)
} else if decideactivity == 2{
noderesponse(nodei)
//fmt.Println("response-",nodei)
} else if decideactivity == 3 {
noderesponseaction(nodei)
} else {
sendmessage(nodei)
}
}
fmt.Println("Session.",j,"--node.",i,"--",nodei)
time.Sleep(300 * time.Millisecond)
if nodei == n - 1 {
// reinitialize()
}
}
}
func resultcompute() {
rand.Seed(time.Now().UnixNano())
nodei := rand.Intn(n)
totalaccept := 1
genuineaccept := 1
for i := 0; i < n*ne; i++ {
if nodemain[nodei][i][9] == 1 && nodemain[nodei][i][10] == 2 {
totalaccept++
}
if nodemain[nodei][i][7] == 1 && nodemain[nodei][i][11] == 1 {
genuineaccept++
}
}
evaluation1 := genuineaccept/totalaccept
evaluation2 := (totalaccept-genuineaccept)/totalaccept
fmt.Println("Genuine Acceptance = ", evaluation1)
fmt.Println("Incorrect Acceptance = ", evaluation2)
for i := 0; i < n; i++ {
for j := 0; j < n*ne; j++ {
if nodemain[i][j][9] == 1 && nodemain[i][j][10] == 2 {
totalaccept++
}
if nodemain[i][j][7] == 1 && nodemain[i][j][11] == 1{
genuineaccept++
}
}
}
overallevaluation1 := genuineaccept/totalaccept
overallevaluation2 := (totalaccept-genuineaccept)/totalaccept
fmt.Println("Overall Genuine Acceptance = ", overallevaluation1)
fmt.Println("Overall Incorrect Acceptance = ", overallevaluation2)
}
func main() {
fmt.Println("######## Initialization Start ##########")
autoserviceupdate()
//resource()
neighbourallot()
nodeinitialize()
factinitialize()
nodetrustinitialize()
scoreinitialize()
fmt.Println("######## Initialization Completed ##########")
for i:= 0; i < n; i++ {
go nodeactivity(i)
}
time.Sleep(3*time.Second)
fmt.Println("######## Process Completed ##########")
resultcompute()
}