// CurrentSession implements the KeybaseService interface for
// KeybaseServiceMeasured.
3124
func (k KeybaseServiceMeasured) CurrentSession(ctx context.Context, sessionID int) (
	sessionInfo idutil.SessionInfo, err error) {
	k.currentSessionTimer.Time(func() {
		sessionInfo, err = k.delegate.CurrentSession(ctx, sessionID)
	})
	return sessionInfo, err
}
395431
func NewSession(config *Config) (*Session, error) {
	session := &Session{
		shutdown: make(chan struct{}),

		// Event channels, same order as api.h
		loggedIn:  make(chan error, 1),
		loggedOut: make(chan struct{}, 1),

		metadataUpdates: make(map[updatesListener]struct{}),

		connectionErrors: make(chan error, 1),
		messagesToUser:   make(chan string, 1),
		notifyMainThread: make(chan struct{}, 1),
		playTokenLost:    make(chan struct{}, 1),

		rawLogMessages: make(chan string, 128),
		logMessages:    make(chan *LogMessage, 128),

		endOfTrack:      make(chan struct{}, 1),
		streamingErrors: make(chan error, 1),

		userInfoUpdates: make(map[updatesListener]struct{}),

		offlineStatusUpdates: make(chan struct{}, 1),
		offlineErrors:        make(chan error, 1),
		credentialsBlobs:     make(chan []byte, 1),
		connectionStates:     make(chan struct{}, 1),

		scrobbleErrors:        make(chan error, 1),
		privateSessionChanges: make(chan bool, 1),

		audioConsumer: config.AudioConsumer,
	}

	if err := session.setupConfig(config); err != nil {
		return nil, err
	}

	// libspotify expects certain methods to be called from the same thread as was
	// used when the sp_session_create was called. Hence we do lock down one
	// thread to only process events and some of these special calls.
	//
	// AFAIK this is the only way we can decide which thread a given goroutine
	// executes on.
	errc := make(chan error, 1)
	go func() {
		// TODO make sure we have enough threads available
		runtime.LockOSThread()

		err := spError(C.sp_session_create(&session.config, &session.sp_session))
		errc <- err
		if err != nil {
			return
		}
		session.processEvents()
	}()

	if err := <-errc; err != nil {
		return nil, err
	}

	go session.processBackground()

	return session, nil
}
1117580
func addSession(key string, app *App) {
	mutex.Lock()
	defer mutex.Unlock()

	sessions[key] = app
}
875095
func newSession(maxAge int) *Session {
	uid, err := uuid.NewV4()
	if err != nil {
		panic(ErrNoSessionID)
	}
	return &Session{
		true, // is new
		internalSession{
			make(map[string]interface{}),
			uid.String(),
			time.Now(),
			time.Duration(maxAge) * time.Second,
		},
	}
}
59278
func NewSessionHandler(xp rpc.Transporter, g *libkb.GlobalContext) *SessionHandler {
	return &SessionHandler{
		BaseHandler:  NewBaseHandler(g, xp),
		Contextified: libkb.NewContextified(g),
	}
}
427570
func NewSession(store Store, name string) *Session {
	return &Session{
		Values:  make(map[interface{}]interface{}),
		store:   store,
		name:    name,
		Options: new(Options),
	}
}
91018
func NewSession(ro *RequestOptions) *Session {
	if ro == nil {
		ro = &RequestOptions{}
	}

	ro.UseCookieJar = true

	return &Session{RequestOptions: ro, HTTPClient: BuildHTTPClient(*ro)}
}
1241979
func (eg *EngineGroup) NewSession() *Session {
	sess := eg.Engine.NewSession()
	sess.sessionType = groupSession
	return sess
}
789860
func (s *RespondToAuthChallengeOutput) SetSession(v string) *RespondToAuthChallengeOutput {
	s.Session = &v
	return s
}
843065
func (c *Context) SetSession(session Session, login bool) {
	session.UserAgent = c.req.UserAgent()
	session.IpAddress = strings.Split(c.req.RemoteAddr, ":")[0]
	session.LastActiveTime = time.Now()
	session.CallCount++

	c.svc.sm.sessions[session.Key] = session
	c.Session = &session

	if login {
		http.SetCookie(c.res, &http.Cookie{
			Name:  soap.SessionCookieName,
			Value: session.Key,
		})

		c.postEvent(&types.UserLoginSessionEvent{
			SessionId: session.Key,
			IpAddress: session.IpAddress,
			UserAgent: session.UserAgent,
			Locale:    session.Locale,
		})
	}
}
780319
func (s *Service) FindSession(ctx context.Context, key string) (*platform.Session, error) {
	result, found := s.sessionKV.Load(key)
	if !found {
		return nil, &platform.Error{
			Code: platform.ENotFound,
			Msg:  platform.ErrSessionNotFound,
		}
	}

	sess := new(platform.Session)
	*sess = result.(platform.Session)

	// TODO(desa): these values should be cached so it's not so expensive to lookup each time.
	f := platform.UserResourceMappingFilter{UserID: sess.UserID}
	mappings, _, err := s.FindUserResourceMappings(ctx, f)
	if err != nil {
		return nil, &platform.Error{
			Err: err,
		}
	}

	ps := make([]platform.Permission, 0, len(mappings))
	for _, m := range mappings {
		p, err := m.ToPermissions()
		if err != nil {
			return nil, &platform.Error{
				Err: err,
			}
		}

		ps = append(ps, p...)
	}
	ps = append(ps, platform.MePermissions(sess.UserID)...)
	sess.Permissions = ps
	return sess, nil
}
200654
func (s *FleetUtilization) SetCurrentPlayerSessionCount(v int64) *FleetUtilization {
	s.CurrentPlayerSessionCount = &v
	return s
}
448192
func NewSessionService() *SessionService {
	return &SessionService{
		FindSessionFn:   func(context.Context, string) (*platform.Session, error) { return nil, fmt.Errorf("mock session") },
		CreateSessionFn: func(context.Context, string) (*platform.Session, error) { return nil, fmt.Errorf("mock session") },
		ExpireSessionFn: func(context.Context, string) error { return fmt.Errorf("mock session") },
		RenewSessionFn: func(ctx context.Context, session *platform.Session, expiredAt time.Time) error {
			return fmt.Errorf("mock session")
		},
	}
}
456355
func (mgr *MemorySessionManager) NewSession() (Session, error) {
	sid, err := mgr.sessionID()
	if err != nil {
		return nil, err
	}
	s := MemorySession{sid: sid, data: make(map[string]interface{}), createdAt: time.Now()}
	mgr.lock.Lock()
	mgr.sessions[sid] = &s
	mgr.lock.Unlock()
	return &s, nil
}
820758
func (b *backend) ResetSession(_ context.Context) {
	b.lock.Lock()
	defer b.lock.Unlock()

	if b.session != nil {
		b.session.Close()
	}

	b.session = nil
}
750488
func (mgr *MemorySessionManager) Session(sid string) (Session, error) {
	mgr.lock.RLock()
	if s, ok := mgr.sessions[sid]; ok {
		s.createdAt = time.Now()
		mgr.lock.RUnlock()
		return s, nil
	}
	mgr.lock.RUnlock()
	return nil, fmt.Errorf("Can not retrieve session with id %s", sid)
}
838288
func Session(ctx context.Context) (interface{}, bool) {
	v := ctx.Value(SessionKey)
	return v, v != nil
}