package network

import (
	"context"
	"log"
	"time"

	"github.com/cretz/bine/tor"
)

// InitTorSession initialize a tor session
func InitTorSession() (t *tor.Tor, dialer *tor.Dialer, dialCancel context.CancelFunc, err error) {
	t, err = tor.Start(nil, nil)
	if err != nil {
		log.Panicf("Failed to start tor: %v", err)
	}
	// Wait at most a minute to start network and get
	dialCtx, dialCancel := context.WithTimeout(context.Background(), time.Minute)

	dialer, err = t.Dialer(dialCtx, nil)
	if err != nil {
		return
	}
	return
}
