Research Article

A Distributed Relation Detection Approach in the Internet of Things

Algorithm 1

Distributed routing tree building algorithm.
   Function: buildRoutingTree(String rID)
(1)  parent = , , toSend = neighbors
(2)  send Msg(“go”, ID, rID, 0) to each object in toSend
   Function: receiveMsg(Msg msg, Node from)
(1)  if  msg.type=“gothen
(2)  if  msg.rID∈RS  and  msg.root    then
(3)    if  msg.depth + depth[msg.rID]   threshold  then
(4)     send Msg(“reverse”,ID,msg.rID,0) to parent and from
(5)    else if  msg.depth  >  depth[msg.rID] then
(6)     send Msg(“reverse”, msg.root, msg.rID, msg.depth+1) to parent
(7)    else
(8)     send Msg(“reverse”, root, msg.rID, depth[msg.rID]) to from
(9)    end
(10)  end
(11)  if  parent=  then
(12)    parent = from, root = msg.root, toSend =
(13)    RS = RS∪  msg.rID , depth[msg.rID]=msg.depth+1,
(14)    if (toSend) then
(15)      send Msg(“continue”, root, msg.rID, ) to from
(16)    else
(17)      send Msg(“stop”, root, msg.rID, ) to from
(18)    end
(19)  else if  parent=from  then
(20)    send Msg(“go”, root, msg.rID, msg.depth+1) to each object in toSend
(21)    visited=, root = msg.root, depth[msg.rID]=msg.depth+1
(22)  else
(23)    send Msg(“no”, root, msg.rID, ) to from
(24)  end
(25)  else if  msg.type=“continue”, “stopornothen
(26)   
(27)   if  msg.type=“continueorstopthen
(28)    
(29)   end
(30)   if  msg.type=“stopornothen
(31)      toSend  
(32)   end
(33)   if  toSend=  then
(34)     if  parent=ID  then
(35)      trigger the relation detection process
(36)     else
(37)      send Msg(“stop”, root, msg.rID, ) to parent
(38)     end
(39)   else  if  visited=toSend  then
(40)      if  parent=ID  then
(41)       send Msg(“go”, ID, msg.rID, 0) to each object in toSend
(42)       visited=
(43)     else
(44)       send Msg(“continue”, root, msg.rID, ) to from
(45)     end
(46)   end
(47)  else if  msg.type=“reversethen
(48)  send Msg(“revserse”, msg.root, msg.rID, msg.depth+1) to parent
(49)  parent = from, root=msg.root, depth[msg.rID] = msg.depth+1
(50)  modify children in parent and current node
(51)  end