Ejemplo n.º 1
0
// tdir = fe templates dir
// sdir = fe static files dir
func MakeFrontEnd(
	tdir, sdir string,
	addr string,
	allow string,
	bank sys.Bank,
	vault vault.Vault,
	myid sys.Id) (*FrontEnd, os.Error) {

	fe := &FrontEnd{
		tdir:     tdir,
		sdir:     sdir,
		bank:     bank,
		vault:    vault,
		adminURL: "http://a." + sys.Host,
		myURL:    sys.MakeURL("", myid, ""),
	}
	err := fe.loadTmpls()
	if err != nil {
		return nil, err
	}
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return nil, err
	}
	fe.wwwclient = http.NewAsyncClient(30e9, 2, 3, 60)
	fe.server = http.NewAsyncServer(l, 20e9, 100)
	fe.server.SetAllowHosts(http.MakeAllowHosts(allow))
	go fe.serveLoop()
	return fe, nil
}
Ejemplo n.º 2
0
func main() {
	fmt.Fprintf(os.Stderr, "Starting "+sys.Name+" Tangra Daemon, Build "+sys.Build+"\n")
	flag.Parse()

	// Setup log writing facility
	if *flagLog == "" {
		fmt.Fprintf(os.Stderr, "tonika-tangrad: You must specify a log file prefix\n")
		os.Exit(1)
	}
	fw_, err := filewriter.MakeFileWriter(*flagLog)
	if err != nil {
		fmt.Fprintf(os.Stderr, "tonika-tangrad: Error creating log file: %s\n", err)
		os.Exit(1)
	}
	fw = fw_

	// Start listening
	l, err := net.Listen("tcp", *flagBind)
	if err != nil {
		fmt.Fprintf(os.Stderr, "tonika-tangrad: Error binding: %s\n", err)
		os.Exit(1)
	}
	s := http.NewAsyncServer(l, 10e9, 240)
	for {
		q, err := s.Read()
		if err == nil {
			go serve(q)
		}
	}
}
Ejemplo n.º 3
0
func MakeServer(bind, dir string, fdlim int) (*Server, os.Error) {
	statPrefix := dir + "/log/towstats"
	logPrefix := dir + "/log/towlog"
	templateDir := dir + "/template"

	// Stats
	stats := &WWWStats{}
	err := filewriter.LatestDecode(statPrefix, stats)
	if err != nil {
		stats = &WWWStats{}
	}
	statwriter, err := filewriter.MakeLatestFileEncoder(statPrefix)
	if err != nil {
		return nil, err
	}
	fmt.Fprintf(os.Stderr, "tonika-wwwd: Starting with Views=%d, Downloads=%d\n",
		stats.Views, stats.Downloads)

	// Logger
	logwriter, err := filewriter.MakeFileWriter(logPrefix)
	if err != nil {
		return nil, err
	}

	// Templates
	tmpl, err := loadTmpl(templateDir, "index.html")
	if err != nil {
		return nil, err
	}

	// HTTP Bind
	l, err := net.Listen("tcp", bind)
	if err != nil {
		return nil, err
	}

	// OK
	s := &Server{
		as:         http.NewAsyncServer(l, 20e9, fdlim),
		dir:        dir,
		logwriter:  logwriter,
		stats:      stats,
		statwriter: statwriter,
		indextmpl:  tmpl,
	}
	go s.statLoop()
	return s, nil
}