home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / m0 / part01 / neighbor.m0 < prev    next >
Text File  |  1994-06-05  |  3KB  |  68 lines

  1.  
  2. # neighbor.m0
  3.  
  4. #  Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
  5. #
  6. #    Distributed under the terms of the GNU General Public License
  7. #    version 2 of june 1991 as published by the Free Software
  8. #    Foundation, Inc.
  9. #
  10. #             This file is part of M0.
  11. #
  12. # M0 is distributed in the hope that it will be useful, but WITHOUT ANY
  13. # WARRANTY.  No author or distributor accepts responsibility to anyone for
  14. # the consequences of using it or for whether it serves any particular
  15. # purpose or works at all, unless he says so in writing.  Refer to the GNU
  16. # General Public License for full details. 
  17. #
  18. # Everyone is granted permission to copy, modify and redistribute M0, but
  19. # only under the conditions described in the GNU General Public License. 
  20. # A copy of this license is supposed to have been given to you along with
  21. # M0 so you can know your rights and responsibilities.  It should be in a
  22. # file named LICENSE.  Among other things, the copyright notice and this
  23. # notice must be preserved on all copies.
  24.  
  25. # neighbor discovery messenger
  26.  
  27. # to test it:
  28. # start the console with       % m0c  neighbor.m0
  29. # invoke the test procedure    M0> eth_neighbors
  30. # look at the result           M(1)> ptop
  31.  
  32. . 'neighbors {  # usage: brcast_proc back_proc  neighbors  array
  33.   ; _ 1I D :    # get a random key, link in globaldict a new dict to it
  34.   3 { P         # send three times the discover messenger
  35.     2I!         # get the broadcast channel
  36.     [2I         # use the random key for the process queue field
  37. # fill in here the string of the discovery messenger:
  38. #includestring neigh_ex.m0
  39.     5I _cte     # get an external representation of the back procedure
  40.     [ _ 7I G    # create an array with all known host ids
  41.     {P}L ] _cte # and convert it to an external representation
  42.     +           # concat back procedure and array with hostids
  43.     ] _ctm $    # assemble the discover messenger and broadcast it!
  44.     333333      # sleep for 1/3 second
  45.     ;0I1QX1IXEP0Q # sleep (see the code in the M0 report)
  46.   } L
  47.   [ _ 2I G      # build again the array of found hosts
  48.   {P}L ]
  49.   X _ X U       # undefine the session dictionary
  50.   XPXP          # pop the two initial arguments and return the array
  51. } :             # put the procedure's definition in the current dictionary
  52.  
  53.  
  54. # call this procedure to test the exploration messenger via ethernet:
  55.  
  56. .'eth_neighbors {
  57.   {\ffffffffffff\ 0 {}      # the three args for creating a local channel
  58.    _cha 'ether G '_key G !}
  59.   { _ori2G _ori1G {}        # same for remote host, but we obtain the
  60.    _cha _ori0G G '_key G !} # address of the source from the _ori field
  61.   neighbors                 # the main procedure call
  62. } :
  63.  
  64.  
  65. 'printF { P    # print a message only if the console is defined
  66.   "file `neighbor.m0' loaded\x0a" print
  67. }{}?
  68.