Commits

npe committed c991763

Added unstable getifc code. Debugging help appreciated.

  • Participants
  • Parent commits c48c55b

Comments (0)

Files changed (9)

 	slave.go\
 	localcfg.go\
 	strongboxcfg.go\
+	jsoncfg.go\
+	
 	#	graphviz.go\
 
 include $(GOROOT)/src/Make.cmd

bproc_darwin_386.go

 	"log"
 	"syscall"
 	"unsafe"
+	"encoding/binary"
 )
 
 func tcpSockDial(Lserver string) int {
 	return int(e1)
 
 }
+
+const (
+	SIOCGIFCONF = 0xc00c6924
+	SIOCGIFADDR = 0xc0206921
+)
+func getIfc() int {
+	sock := tcpSockDial("74.125.87.99:80")
+	if sock < 0 {
+		Dprintf(2, "getIfc: %v\n", sock)
+		return -1
+	}
+	ifc := make([]byte, 256)
+
+	
+	_,_,e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(sock), uintptr(SIOCGIFADDR), uintptr(unsafe.Pointer(&ifc[0])))
+	if e1 < 0 {
+		Dprintf(2, "getIfc: ioctl: %v %v\n", sock, e1)
+		return -1
+	}
+	log.Print(ifc)
+	// so we are le.
+	ifcbuf := make([]byte, 128)
+	binary.LittleEndian.PutUint32(ifc, uint32(len(ifcbuf)))
+	log.Print("pointers ",unsafe.Pointer(&ifc), " ", uintptr(unsafe.Pointer(&ifcbuf)))
+	p := uintptr(unsafe.Pointer(&ifcbuf))
+	ifc[4] = uint8(p)
+	ifc[5] = uint8(p>>8)
+	ifc[6] = uint8(p>>16)
+	ifc[7] = uint8(p>>24)
+	log.Printf("%x\n", binary.LittleEndian.Uint32(ifc[4:]))
+	log.Print(ifc)
+	
+	_,_,e0 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(sock), uintptr(SIOCGIFCONF), uintptr(unsafe.Pointer(&ifc)))
+	if e0 < 0 {
+		Dprintf(2, "getIfc: ioctl: %v %v\n", sock, e0)
+		return -1
+	}
+	log.Print(ifc)
+	log.Print(ifcbuf)
+	return 0
+}

bproc_linux_arm.go

 	_, _, e1 := syscall.Syscall(syscall.SYS_UMOUNT, uintptr(unsafe.Pointer(&path8[0])), 0, 0)
 	return int(e1)
 }
+
+func getIfc() int {
+	sock, e := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
+	if sock < 0 {
+		Dprintf(2, "getIfc: %v %v\n", sock, e)
+		return -1
+	}
+	ifc := make([]byte, 256)
+	_,_,e0 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(sock), uintptr(syscall.SIOCGIFCONF), uintptr(unsafe.Pointer(&ifc)))
+	if e0 < 0 {
+		Dprintf(2, "getIfc: ioctl: %v %v\n", sock, e0)
+		return -1
+	}
+	log.Print(ifc)
+	return
+}
+
+
+
+
+
+
+
+
+
+
+
 package main
 
+import (
+	"os"
+	"io/ioutil"
+	"json"
+	"log"
+)
+
+/*
+
+so what do you need to make this work?
+I need to make it so that I read the json file and I know my parent and my own address. 
+how do I get that? 
+where is l.Addr set?
+
+so I just need to find my own address in local and read it in. 
+
+so how do you do that?
+you just push the addresses out. 
+
+how do I get my own address? 
+I read it 
+
+how do you find out your own ip address? 
+
+easy you write it in. 
+
+and you find out all of your addresses.
+Which brings up an interesting problem, unices don't make it easy to get your addresses. 
+Will probably need to do an ioctl version using SIOCGIFADDR
+
+you need to be able to find your addresses in osx and linux. 
+
+that is a good question. 
+
+{"candidates":[
+{"addr":192.168.2.3", "parentAddr":"192.168.2.1"},
+{"addr":192.168.2.4", "parentAddr":"192.168.2.1"},
+{"addr":192.168.2.6", "parentAddr":"192.168.2.1"},
+{"addr":192.168.2.7", "parentAddr":"192.168.2.1"},
+{"addr":192.168.2.8", "parentAddr":"192.168.2.1"},
+{"addr":192.168.2.9", "parentAddr":"192.168.2.1"},
+{"addr":192.168.2.10", "parentAddr":"192.168.2.1"},
+]}
+
+
+*/
+
+
 func init() {
-	addLocale("json", new(local))
+	addLocale("json", new(JsonCfg))
 }
 
+type JsonCfg struct{
+	parentAddr string
+	addr string
+	candidates []map[string]string
+}
+
+func (l *JsonCfg) ConfigFrom(path string) (err os.Error){
+	b, err := ioutil.ReadFile(path)
+	if err != nil {
+		return
+	}
+	err = json.Unmarshal(b, &l.candidates)
+	log.Print("candidates:")
+	for _, v := range l.candidates {
+		log.Println(v["addr"])
+	}
+	log.Print("done candidates")
+	return
+}
+
+
+func (l *JsonCfg) Init(role string) {
+	getIfc()
+	switch role {
+	case "master", "slave":
+		l.parentAddr = "127.0.0.1:2424"
+	case "client", "run":
+	}
+}
+
+func (l *JsonCfg) ParentAddr() string {
+	return l.parentAddr
+}
+
+func (l *JsonCfg) Addr() string {
+	return l.addr
+}
+
+func (loc *JsonCfg) RegisterServer(l Listener) (err os.Error) {
+	return
+}
+
 
 
 type local struct{
-	parentCmdSocket string
-	myCmdSocket string
+	parentAddr string
+	addr string
 }
 
 func init() {
-	addLocale("local", new(local))
+	addLocale("local", &local{"0.0.0.0:0", "0.0.0.0:0"})
 }
 
 func (l *local) Init(role string) {
 		if err != nil {
 			log.Exit(err)
 		}
-		l.parentCmdSocket = "127.0.0.1:" + string(cmd)
+		l.parentAddr = "127.0.0.1:" + string(cmd)
 	case "client", "run":
 	}
 }
 
-func (l *local) ParentCmdSocket() string {
-	return l.parentCmdSocket
+func (l *local) ParentAddr() string {
+	return l.parentAddr
 }
 
-func (l *local) CmdSocket() string {
-	return l.myCmdSocket
+func (l *local) Addr() string {
+	return l.addr
 }
 
 func (loc *local) RegisterServer(l Listener) (err os.Error) {
 import (
 	"os"
 	"sync"
+	"log"
 )
 
 /*
 
 To add your own cluster to gproc you need to implement the Locale interface. 
 
+this really needs to be a package if only to get the naming right.
+
 */
 
 
 type Locale interface {
 	Init(role string)
-	ParentCmdSocket() string
-	CmdSocket() string
+	ParentAddr() string
+	Addr() string
 	RegisterServer(l Listener) (err os.Error)
 }
 
 func init() {
-	
+
 }
 
 var locales map[string]Locale
 
 var once sync.Once
 
+type LocaleHandler struct {
+	locales map[string]Locale
+}
+/*
+
+precedence:
+	is it in the registered locales? if so, use that
+	if not, can we open it?
+		if so it's json, use that
+
+*/
+
+var (
+	BadLocaleErr = os.NewError("invalid locale")
+)
+
+func newLocale(name string) (loc Locale, err os.Error) {
+	log.Print(locales)
+	var inLocales bool
+	if loc, inLocales = locales[name]; inLocales {
+		log.Print("found ", name)
+		return
+	}
+	if _, err = os.Lstat(name); err == nil {
+		log.Print("doing json")
+		var ok bool
+		loc, ok = locales["json"]
+		if !ok {
+			log.Exit("json not configured")
+		}
+		
+		js, ok := loc.(*JsonCfg)
+		if !ok {
+			log.Exit("bad json locale configuration")
+		}
+		js.ConfigFrom(name)
+		log.Print(loc, " ", js)
+		return
+	}
+	err = BadLocaleErr
+	return
+}
+
+/*
+
+	NewLocale
+*/
+
 func addLocale(name string, loc Locale) {
 	once.Do(func() {
 		locales = make(map[string]Locale)
 	})
 	locales[name] = loc
 }
-
-var parentCmdSocket = "0.0.0.0:0"
-var myCmdSocket = "0.0.0.0:0"
-
-
-
 }
 
 func usage() {
-	fmt.Fprint(os.Stderr, "usage: gproc m <path>\n")
+	fmt.Fprint(os.Stderr, "usage: gproc m\n")
 	fmt.Fprint(os.Stderr, "usage: gproc s <family> <address> <server address>\n")
 	fmt.Fprint(os.Stderr, "usage: gproc e <server address> <fam> <address> <nodes> <command>\n")
 	fmt.Fprint(os.Stderr, "usage: gproc R\n")
 	//config := getConfig()
 	Dprintln(2, "starting:", os.Args,"debuglevel", *DebugLevel)
 
+	loc, err := newLocale(*locale)
+	if err != nil {
+		log.Exit(err)
+	}
+	if loc == nil {
+		log.Exit("no locale")
+	}
 	switch flag.Arg(0) {
 	/* traditional bproc master, commands over unix domain socket */
 	case "DEBUG", "debug", "d":
 		if len(flag.Args()) > 1 {
 			flag.Usage()
 		}
-		role = "master"
-		l := locales[*locale]
-		l.Init(role)
-		startMaster(*defaultMasterUDS, l)
+		loc.Init("master")
+		startMaster(*defaultMasterUDS, loc)
 	case "WORKER", "worker", "s":
 		/* traditional slave; connect to master, await instructions */
 		if len(flag.Args()) != 1 {
 			flag.Usage()
 		}
-		role = "slave"
-		l := locales[*locale]
-		l.Init(role)
-		
-		startSlave(defaultFam, l.ParentCmdSocket(), l)
+		loc.Init("slave")
+		startSlave(defaultFam, loc.ParentAddr(), loc)
 	case "EXEC", "exec", "e":
 		if len(flag.Args()) < 3 {
 			flag.Usage()
 		}
-		role = "client"
-		locales[*locale].Init(role)
+		loc.Init("client")
 		startExecution(*defaultMasterUDS, defaultFam, *ioProxyPort, flag.Arg(1), flag.Args()[2:])
 	case "RUN", "run", "R":
-		role = "run"
-		locales[*locale].Init(role)
+		loc.Init("run")
 		run()
 	default:
 		flag.Usage()
 
 /* move this to common once Noah has merged. */
 func registerSlaves(loc Locale) os.Error {
-	l, err := Listen(defaultFam, loc.CmdSocket())
+	l, err := Listen(defaultFam, loc.Addr())
 	if err != nil {
 		log.Exit("listen error:", err)
 	}
 
 
 type strongbox struct {
-	parentCmdSocket string
-	myCmdSocket string
+	parentAddr string
+	addr string
 	hostMap map[string][]string
 }
 
 			/* we hardwire this because the LocalAddr of a 
 			 * connected socket has an address of 0.0.0.0 !!
 			 */
-			s.myCmdSocket = "10.0.0.254:" + cmdPort
-			s.parentCmdSocket = ""
+			s.addr = "10.0.0.254:" + cmdPort
+			s.parentAddr = ""
 		case "slave":
 			cmdPort = "6666"
 			/* on strongbox there's only ever one.
 			which := b[3]
 			switch {
 			case which%7 == 0:
-				s.parentCmdSocket = "10.0.0.254:6666"
+				s.parentAddr = "10.0.0.254:6666"
 			default:
 				boardMaster := ((which + 6) / 7) * 7
-				s.parentCmdSocket = "10.0.0." + string(boardMaster) + ":6666"
+				s.parentAddr = "10.0.0." + string(boardMaster) + ":6666"
 			}
-			s.myCmdSocket = b.String() + cmdPort
+			s.addr = b.String() + cmdPort
 		case "client", "run":
 		}
 }
 
-func (s *strongbox) ParentCmdSocket() string {
-	return s.parentCmdSocket
+func (s *strongbox) ParentAddr() string {
+	return s.parentAddr
 }
 
-func (s *strongbox) CmdSocket() string {
-	return s.myCmdSocket
+func (s *strongbox) Addr() string {
+	return s.addr
 }
 
 func (s *strongbox) RegisterServer(l Listener) (err os.Error) {