Esempio n. 1
0
func WithConnector(t *testing.T, user string, fc func(c *transfer.Connector)) {
	repo.WithRepo(t, user, user+"pass", func(rp *repo.Repository) {
		if err := rp.IPFS.Online(); err != nil {
			t.Errorf("Cannot go online with IPFS repo: %v", err)
			return
		}

		lay := moose.NewLayer(rp.IPFS, context.Background())
		con := transfer.NewConnector(lay, rp)

		if err := con.Connect(); err != nil {
			t.Errorf("Cannot connect: %v", err)
			return
		}

		con.WaitForPool()

		t.Logf("Entering test for %s's connector", user)
		fc(con)
		t.Logf("Leaving test for %s's connector", user)

		if err := con.Disconnect(); err != nil {
			t.Errorf("Cannot disconnect: %v", err)
			return
		}
	})
}
Esempio n. 2
0
// Summon creates a new up and running Server instance
func Summon(pwd, repoFolder string, port int) (*Server, error) {
	// Load the on-disk repository:
	log.Infof("Opening repo: %s", repoFolder)
	rep, err := repo.Open(pwd, repoFolder)
	if err != nil {
		log.Error("Could not load repository: ", err)
		return nil, err
	}

	// Listen for incoming connections.
	addr := fmt.Sprintf("localhost:%d", port)
	listener, err := net.Listen("tcp", addr)
	if err != nil {
		log.Error("Error listening:", err.Error())
		return nil, err
	}

	if err != nil {
		return nil, err
	}

	// Close the listener when the application closes.
	log.Info("Listening on ", addr)
	ctx, cancel := context.WithCancel(context.Background())
	layer := moose.NewLayer(rep.IPFS, ctx)

	daemon := &Server{
		Repo:           rep,
		Mounts:         fuse.NewMountTable(rep.OwnStore),
		MetaHost:       transfer.NewConnector(layer, rep),
		signals:        make(chan os.Signal, 1),
		listener:       listener,
		maxConnections: make(chan allowOneConn, MaxConnections),
		ctx:            ctx,
	}

	go daemon.loop(cancel)

	if err := daemon.Connect(); err != nil {
		return nil, err
	}

	return daemon, nil
}