// Create a new DryMartini object with its own kademlia and RPC server func NewDryMartini(listenStr string, keylen int) *DryMartini { var err error var s *rpc.Server var dm *DryMartini dm = new(DryMartini) dm.EasyNewFlowIndex = 0 //Initialize key pair dm.KeyPair, err = rsa.GenerateKey(rand.Reader, keylen) if err != nil { dbg.Printf("Failed to generate key! %s", true, err) panic(1) } //Initialize flow struct dm.Bartender = make(map[UUID]MartiniPick) dm.Momento = make(map[UUID][]FlowIDSymmKeyPair) dm.MapFlowIndexToFlowID = make(map[int]FlowInfo) var host net.IP var port uint16 host, port, err = kademlia.AddrStrToHostPort(listenStr) //Initialize our Kademlia //portStr := strconv.FormatUint(uint64(port), 10) //var rpcPathStr string = kademlia.RpcPath+portStr var rpcPathStr = "junk" dbg.Printf("making new Kademlia with listenStr:%s, rpcPath\n", Verbose, listenStr, rpcPathStr) dm.KademliaInst, s = kademlia.NewKademlia(listenStr, &rpcPathStr) kademlia.BucketsAsArray(dm.KademliaInst) //myMartiniContact <- ip, port, public key dm.myMartiniContact.NodeIP = host.String() dm.myMartiniContact.NodePort = port dm.myMartiniContact.PubKey = dm.KeyPair.PublicKey.N.String() dm.myMartiniContact.PubExp = dm.KeyPair.PublicKey.E dbg.Printf("NewDryMartini: making new Kademlia with NodeIP: %s. NodePort:%d\n", Verbose, dm.myMartiniContact.NodeIP, dm.myMartiniContact.NodePort) /* if Verbose { dbg.Printf("NodeIP: %s\n", dm.myMartiniContact.NodeIP) dbg.Printf("NodePort: %d\n", dm.myMartiniContact.NodePort) dbg.Printf("PubKey: %s\n", dm.myMartiniContact.PubKey) dbg.Printf("PubExp: %d\n", dm.myMartiniContact.PubKey) }*/ //register err = s.Register(dm) if err != nil { dbg.Printf("Failed to register Drymartini! %s", true, err) panic(1) } return dm }
func main() { kListenStr := flag.String("l", "localhost:8000", "the address:port the kademlia instance will operate over") htmlDirPath := flag.String("d", "/home/jch570/public_html/", "the path to the directory where html files are served. file is written out to this dir") htmlFileName := flag.String("f", "dms.html", "filename where drymartini info will be written out") flag.Parse() listenStr := *kListenStr log.Printf("dmTracker listening on:%s\n", listenStr) var junk = "junk" kademInst, _ := kademlia.NewKademlia(listenStr, &junk) log.Printf("dmTracker checking querying initial core: %+v\n", coreKadems) // commenting out, for testing just going to use localhost:8000-8004 for _, apPair := range coreKadems { ipList, err := net.LookupIP(apPair.addr) if err != nil { log.Printf("error looking up addr:%s. Err:%s\n", apPair.addr, err) } kademlia.MakePingCall(kademInst, ipList[0], apPair.port) } //test should trash soon for i := 0; i < 5; i++ { ipList, err := net.LookupIP("localhost") if err != nil { log.Printf("error looking up addr\n") } kademlia.MakePingCall(kademInst, ipList[0], uint16(8000+i)) } //end junk kademlia.DoJoin(kademInst) var contacts []kademlia.Contact contacts = kademlia.BucketsAsArray(kademInst) log.Printf("local buckets as array:\n %+v\n", contacts) f, err := os.Create(*htmlDirPath + *htmlFileName) if err != nil { //"./testoutput"); if(err!=nil){// log.Printf("error creating file:%s\n", err) os.Exit(1) } f.Write([]byte("DryMartinis found:\n")) var c kademlia.Contact for _, c = range contacts { f.Write([]byte(c.AsString() + "\n")) } f.Write([]byte("last updated: " + time.Now().String())) f.Close() }