コード例 #1
0
ファイル: ramfs.go プロジェクト: KevinMGranger/go9p
func main() {
	var err error
	var l *p.Logger

	flag.Parse()
	rsrv.user = p.OsUsers.Uid2User(os.Geteuid())
	rsrv.group = p.OsUsers.Gid2Group(os.Getegid())
	rsrv.blksz = *blksize
	rsrv.blkchan = make(chan []byte, 2048)
	rsrv.zero = make([]byte, rsrv.blksz)

	root := new(RFile)
	err = root.Add(nil, "/", rsrv.user, nil, p.DMDIR|0777, root)
	if err != nil {
		goto error
	}

	l = p.NewLogger(*logsz)
	rsrv.srv = srv.NewFileSrv(&root.File)
	rsrv.srv.Dotu = true
	rsrv.srv.Debuglevel = *debug
	rsrv.srv.Start(rsrv.srv)
	rsrv.srv.Id = "ramfs"
	rsrv.srv.Log = l

	err = rsrv.srv.StartNetListener("tcp", *addr)
	if err != nil {
		goto error
	}
	return

error:
	log.Println(fmt.Sprintf("Error: %s", err))
}
コード例 #2
0
ファイル: tlsramfs.go プロジェクト: KevinMGranger/go9p
func main() {
	var err error

	flag.Parse()
	rsrv.user = p.OsUsers.Uid2User(os.Geteuid())
	rsrv.group = p.OsUsers.Gid2Group(os.Getegid())
	rsrv.blksz = *blksize
	rsrv.blkchan = make(chan []byte, 2048)
	rsrv.zero = make([]byte, rsrv.blksz)

	root := new(RFile)
	err = root.Add(nil, "/", rsrv.user, nil, p.DMDIR|0777, root)
	if err != nil {
		log.Println(fmt.Sprintf("Error: %s", err))
		return
	}

	l := p.NewLogger(*logsz)
	rsrv.srv = srv.NewFileSrv(&root.File)
	rsrv.srv.Dotu = true
	rsrv.srv.Debuglevel = *debug
	rsrv.srv.Start(rsrv.srv)
	rsrv.srv.Id = "ramfs"
	rsrv.srv.Log = l

	cert := make([]tls.Certificate, 1)
	cert[0].Certificate = [][]byte{testCertificate}
	cert[0].PrivateKey = testPrivateKey

	ls, oerr := tls.Listen("tcp", *addr, &tls.Config{
		Rand:               rand.Reader,
		Certificates:       cert,
		CipherSuites:       []uint16{tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA},
		InsecureSkipVerify: true,
	})
	if oerr != nil {
		log.Println("can't listen:", oerr)
		return
	}

	err = rsrv.srv.StartListener(ls)
	if err != nil {
		log.Println(fmt.Sprintf("Error: %s", err))
		return
	}
	return
}
コード例 #3
0
ファイル: srv.go プロジェクト: KevinMGranger/go9p
// The Start method should be called once the file server implementor
// initializes the Srv struct with the preferred values. It sets default
// values to the fields that are not initialized and creates the goroutines
// required for the server's operation. The method receives an empty
// interface value, ops, that should implement the interfaces the file server is
// interested in. Ops must implement the ReqOps interface.
func (srv *Srv) Start(ops interface{}) bool {
	if _, ok := (ops).(ReqOps); !ok {
		return false
	}

	srv.ops = ops
	if srv.Upool == nil {
		srv.Upool = p.OsUsers
	}

	if srv.Msize < p.IOHDRSZ {
		srv.Msize = p.MSIZE
	}

	if srv.Log == nil {
		srv.Log = p.NewLogger(1024)
	}

	if sop, ok := (interface{}(srv)).(StatsOps); ok {
		sop.statsRegister()
	}

	return true
}