Exemplo n.º 1
0
func main() {
	// Nasty argument handling - I'm too cool to care.
	if len(os.Args) < 2 {
		fmt.Printf("Too few arguments\n")
		return
	}

	addr := os.Args[1]

	// We shut up by default.
	var verbosity = fileserver.Quiet

	// See if the user wanted a different verbosity level (If he does, he's most likely KL).
	if len(os.Args) > 2 {
		switch os.Args[2] {
		case "quiet":
			verbosity = fileserver.Quiet
		case "chatty":
			verbosity = fileserver.Chatty
		case "loud":
			verbosity = fileserver.Loud
		case "obnoxious":
			verbosity = fileserver.Obnoxious
		case "debug":
			verbosity = fileserver.Debug
		default:
			fmt.Printf("Unknown verbosity level %s\n", os.Args[3])
			return
		}
	}

	// We don't really care about them, but we have to set them.
	user := "******"
	group := "none"

	root := trees.NewSyntheticDir("net", 0777, user, group)
	root.Add("tcp", net9p.NewTCPDir(user, group))
	root.Add("udp", net9p.NewUDPDir(user, group))
	root.Add("cs", net9p.NewCSFile(user, group))

	l, err := net.Listen("tcp", addr)
	if err != nil {
		log.Fatalf("Unable to listen: %v", err)
	}

	log.Printf("Starting ipfs at %s", addr)

	for {
		conn, err := l.Accept()
		if err != nil {
			log.Printf("Error: %v", err)
			return
		}

		f := fileserver.New(conn, root, nil)
		f.Verbosity = verbosity
		go f.Serve()
	}
}
Exemplo n.º 2
0
func main() {
	go func() {
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()
	if len(os.Args) < 4 {
		fmt.Printf("Too few arguments\n")
		usage()
		return
	}

	user := os.Args[1]
	group := os.Args[2]
	addr := os.Args[3]

	var verbosity = fileserver.Quiet
	if len(os.Args) > 4 {
		switch os.Args[4] {
		case "quiet":
			verbosity = fileserver.Quiet
		case "chatty":
			verbosity = fileserver.Chatty
		case "loud":
			verbosity = fileserver.Loud
		case "obnoxious":
			verbosity = fileserver.Obnoxious
		case "debug":
			verbosity = fileserver.Debug
		default:
			fmt.Printf("Unknown verbosity level %s\n", os.Args[4])
			usage()
			return
		}
	}

	root := trees.NewSyntheticDir("/", 0777, user, group)
	l, err := net.Listen("tcp", addr)
	if err != nil {
		log.Fatalf("Unable to listen: %v", err)
	}

	log.Printf("Starting ramfs at %s", addr)
	for {
		conn, err := l.Accept()
		if err != nil {
			log.Printf("Error: %v", err)
			return
		}

		f := fileserver.New(conn, root, nil)
		f.Verbosity = verbosity
		go f.Serve()
	}
}
Exemplo n.º 3
0
func main() {
	if len(os.Args) < 5 {
		fmt.Printf("Too few arguments\n")
		usage()
		return
	}

	path := os.Args[1]
	user := os.Args[2]
	group := os.Args[3]
	addr := os.Args[4]

	var verbosity = fileserver.Quiet
	if len(os.Args) > 5 {
		switch os.Args[5] {
		case "quiet":
			verbosity = fileserver.Quiet
		case "chatty":
			verbosity = fileserver.Chatty
		case "loud":
			verbosity = fileserver.Loud
		case "obnoxious":
			verbosity = fileserver.Obnoxious
		case "debug":
			verbosity = fileserver.Debug
		default:
			fmt.Printf("Unknown verbosity level %s\n", os.Args[4])
			usage()
			return
		}
	}

	root := trees.NewProxyFile(path, "", user, group)
	l, err := net.Listen("tcp", addr)
	if err != nil {
		log.Fatalf("Unable to listen: %v", err)
	}

	log.Printf("Starting exportfs at %s", addr)

	for {
		conn, err := l.Accept()
		if err != nil {
			log.Printf("Error: %v", err)
			return
		}

		f := fileserver.New(conn, root, nil)
		f.Verbosity = verbosity
		go f.Serve()
	}
}