Commits

npe  committed c48c55b

added config files

  • Participants
  • Parent commits 6b14d5d

Comments (0)

Files changed (3)

+package main
+
+func init() {
+	addLocale("json", new(local))
+}
+
+package main
+
+import (
+	"os"
+	"strings"
+	"io/ioutil"
+	"log"
+)
+
+
+type local struct{
+	parentCmdSocket string
+	myCmdSocket string
+}
+
+func init() {
+	addLocale("local", new(local))
+}
+
+func (l *local) Init(role string) {
+	switch role {
+	case "master", "slave":
+		cmd, err := ioutil.ReadFile(srvAddr)
+		if err != nil {
+			log.Exit(err)
+		}
+		l.parentCmdSocket = "127.0.0.1:" + string(cmd)
+	case "client", "run":
+	}
+}
+
+func (l *local) ParentCmdSocket() string {
+	return l.parentCmdSocket
+}
+
+func (l *local) CmdSocket() string {
+	return l.myCmdSocket
+}
+
+func (loc *local) RegisterServer(l Listener) (err os.Error) {
+	/* take the port only -- the address shows as 0.0.0.0 */
+	addr := strings.Split(l.Addr().String(), ":", 2)
+	return ioutil.WriteFile(srvAddr, []byte(addr[1]), 0644)
+}

File strongboxcfg.go

+package main
+
+import (
+	"os"
+	"net"
+	"log"
+	"strconv"
+)
+
+
+type strongbox struct {
+	parentCmdSocket string
+	myCmdSocket string
+	hostMap map[string][]string
+}
+
+func init() {
+	addLocale("strongbox", new(strongbox))
+}
+
+func (s *strongbox) getIPs() []string {
+	hostName, err := os.Hostname()
+	if err != nil {
+		log.Exit(err)
+	}
+	if addrs, ok := s.hostMap[hostName]; ok {
+		return addrs
+	}
+	_, addrs, err := net.LookupHost(hostName)
+	if err != nil {
+		log.Exit(err)
+	}
+	return addrs
+}
+
+func (s *strongbox) initHostTable() {
+	s.hostMap = make(map[string][]string)
+	for i := 0; i < 197; i++ {
+		n := strconv.Itoa(i)
+		host := "cn" + n
+		ip := "10.0.0." + n
+		s.hostMap[host] = []string{ip}
+	}
+}
+
+func (s *strongbox) Init(role string) {
+		s.initHostTable()
+		addrs := s.getIPs()
+		switch role {
+		case "master":
+			cmdPort = "6666"
+			/* 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 = ""
+		case "slave":
+			cmdPort = "6666"
+			/* on strongbox there's only ever one.
+			 * pick out the lowest-level octet.
+			 */
+			b := net.ParseIP(addrs[0]).To4()
+			which := b[3]
+			switch {
+			case which%7 == 0:
+				s.parentCmdSocket = "10.0.0.254:6666"
+			default:
+				boardMaster := ((which + 6) / 7) * 7
+				s.parentCmdSocket = "10.0.0." + string(boardMaster) + ":6666"
+			}
+			s.myCmdSocket = b.String() + cmdPort
+		case "client", "run":
+		}
+}
+
+func (s *strongbox) ParentCmdSocket() string {
+	return s.parentCmdSocket
+}
+
+func (s *strongbox) CmdSocket() string {
+	return s.myCmdSocket
+}
+
+func (s *strongbox) RegisterServer(l Listener) (err os.Error) {
+	return
+}