func (s *sessionCache) GetIfExist(key p2pcrypto.PublicKey) (NetworkSession, error) {
	s.sMtx.Lock()
	ns, ok := s.sessions[key]
	s.sMtx.Unlock()
	if ok {
		return ns.session, nil
	}
	return nil, errors.New("not found")
}
GetIfExist gets a session from the cache based on address
package net
import (
	"errors"
	"sync"
	"time"
	"github.com/libonomy/libonomy-p2p/p2p/p2pcrypto"
)
const maxSessions = 2048
type storedSession struct {
	session NetworkSession
	ts      time.Time
}
type dialSessionFunc func(pubkey p2pcrypto.PublicKey) NetworkSession
type sessionCache struct {
	dialFunc dialSessionFunc
	sMtx     sync.Mutex
	sessions map[p2pcrypto.PublicKey]*storedSession
}
func newSessionCache(dialFunc dialSessionFunc) *sessionCache {
	return &sessionCache{dialFunc: dialFunc,
		sMtx:     sync.Mutex{},
		sessions: make(map[p2pcrypto.PublicKey]*storedSession)}
}