package bridge

import (
	
	
	
	
)

type Pool struct {
	Connections map[string]*Session
	sync.Mutex
}
type TunnelPool struct {
	Connections map[string]*Tunnel
	sync.Mutex
}

var (
	Sessions Pool       = Pool{Connections: make(map[string]*Session)}
	Tunnels  TunnelPool = TunnelPool{Connections: make(map[string]*Tunnel)}
)

// Get connection from pool
func ( *Pool) (,  string) (*Session, error) {
	if ,  := .Connections[+];  {
		return , nil
	} else {
		return nil, errors.New("connection does not exist")
	}
}

// Set connection on pool
func ( *Pool) (,  string,  *Session) {
	.Lock()
	defer .Unlock()
	.Connections[+] = 
}

// GetRaw connection object from pool
func ( *Pool) (, ,  string) (*Session, error) {
	if ,  := .Connections[++];  {
		.LastConnection = time.Now()
		return , nil
	} else {
		return nil, errors.New("connection does not exist")
	}
}

// SetRaw connection object on pool
func ( *Pool) (, ,  string,  *Session) {
	.Lock()
	defer .Unlock()
	.Connections[++] = 
}

// Delete connection object from pool
func ( *Pool) ( string) {
	.Lock()
	defer .Unlock()
	delete(.Connections, )
}

// Get Tunnel connection from pool
func ( *TunnelPool) (, ,  string) (*Tunnel, error) {
	if ,  := Tunnels.Connections[+":"++":"+];  {
		.LastConnection = time.Now()
		return , nil
	} else {
		return nil, errors.New("tunnel does not exist")
	}
}

// Set Tunnel connection to pool
func ( *TunnelPool) (, ,  string,  *Tunnel) {
	.Lock()
	defer .Unlock()
	Tunnels.Connections[+":"++":"+] = 
}

// Delete Tunnel connection from pool
func ( *TunnelPool) ( string) {
	.Lock()
	defer .Unlock()
	.Connections[] = nil
	delete(.Connections, )
}

// VerifyAuth verifies key when connecting
func (, , , ,  string) bool {
	if  == "ssh" {
		return VerifySSH(, , , )
	} else if  == "ssh_certificate" {
		return VerifySSHCertificate(, , , )
	} else if strings.Contains(, "winrm") {
		 := true
		if strings.Contains(, "insecure") {
			 = false
		}

		return VerifyWinRm(, , , , )
	}
	return true
}