<commit_before>package crammd5

import (
	"fmt"
	"sync"

	"code.google.com/p/gogoprotobuf/proto"
	log "github.com/golang/glog"
	"github.com/mesos/mesos-go/auth"
	mesos "github.com/mesos/mesos-go/mesosproto"
	"github.com/mesos/mesos-go/messenger"
	"github.com/mesos/mesos-go/upid"
	"golang.org/x/net/context"
)

var (
	pidLock        sync.Mutex
	pid            int
	supportedMechs map[string]struct{}
)

type statusType int

const (
	READY statusType = iota
	STARTING
	STEPPING
	COMPLETED
	FAILED
	ERROR
	DISCARDED
)

type authenticateeProcess struct {
	*messenger.MesosMessenger
	credential mesos.Credential
	client     upid.UPID
	status     statusType
	done       chan struct{}
	result     error
	mech       *mechanism
	stepFn     stepFunc
}

type handlerFn func(ctx context.Context, from *upid.UPID, pbMsg proto.Message)

func init() {
	supportedMechs = make(map[string]struct{})
	supportedMechs["CRAM-MD5"] = struct{}{}
}

func nextPid() int {
	pidLock.Lock()
	defer pidLock.Unlock()
	pid++
	return pid
}

func Authenticatee(ctx context.Context, pid, client upid.UPID, credential mesos.Credential) <-chan error {

	c := make(chan error, 1)
	f := func() error {
		auth := newAuthenticatee(ctx, client, credential)
		auth.authenticate(ctx, pid)

		select {
		case <-ctx.Done():
			<-auth.done
			return ctx.Err()
		case <-auth.done:
			return auth.result
		}
	}
	go func() { c <- f() }()
	return c
}

func newAuthenticatee(ctx context.Context, client upid.UPID, credential mesos.Credential) *authenticateeProcess {
	pid := &upid.UPID{ID: fmt.Sprintf("crammd5_authenticatee(%d)", nextPid())}
	transport := messenger.NewMesosMessenger(pid)
	proc := &authenticateeProcess{
		MesosMessenger: transport,
		client:         client,
		credential:     credential,
		status:         READY,<commit_msg>stop the authentication transport upon termination<commit_after>package crammd5

import (
	"fmt"
	"sync"

	"code.google.com/p/gogoprotobuf/proto"
	log "github.com/golang/glog"
	"github.com/mesos/mesos-go/auth"
	mesos "github.com/mesos/mesos-go/mesosproto"
	"github.com/mesos/mesos-go/messenger"
	"github.com/mesos/mesos-go/upid"
	"golang.org/x/net/context"
)

var (
	pidLock        sync.Mutex
	pid            int
	supportedMechs map[string]struct{}
)

type statusType int

const (
	READY statusType = iota
	STARTING
	STEPPING
	COMPLETED
	FAILED
	ERROR
	DISCARDED
)

type authenticateeProcess struct {
	*messenger.MesosMessenger
	credential mesos.Credential
	client     upid.UPID
	status     statusType
	done       chan struct{}
	result     error
	mech       *mechanism
	stepFn     stepFunc
}

type handlerFn func(ctx context.Context, from *upid.UPID, pbMsg proto.Message)

func init() {
	supportedMechs = make(map[string]struct{})
	supportedMechs["CRAM-MD5"] = struct{}{}
}

func nextPid() int {
	pidLock.Lock()
	defer pidLock.Unlock()
	pid++
	return pid
}

func Authenticatee(ctx context.Context, pid, client upid.UPID, credential mesos.Credential) <-chan error {

	c := make(chan error, 1)
	f := func() error {
		auth := newAuthenticatee(ctx, client, credential)
		if auth.status == READY {
			defer auth.Stop()
		}
		auth.authenticate(ctx, pid)

		select {
		case <-ctx.Done():
			<-auth.done
			return ctx.Err()
		case <-auth.done:
			return auth.result
		}
	}
	go func() { c <- f() }()
	return c
}

func newAuthenticatee(ctx context.Context, client upid.UPID, credential mesos.Credential) *authenticateeProcess {
	pid := &upid.UPID{ID: fmt.Sprintf("crammd5_authenticatee(%d)", nextPid())}
	transport := messenger.NewMesosMessenger(pid)
	proc := &authenticateeProcess{
		MesosMessenger: transport,
		client:         client,
		credential:     credential,
		status:         READY,
{'fraction_non_alphanumeric': 0.12248230811105063, 'fraction_numerical': 0.002177463255307567, 'mean_word_length': 3.6934865900383143, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3718313', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1367, 'n_words': 287}