cwtch/peer/connections/peerpeerconnection.go

43 lines
1.0 KiB
Go
Raw Normal View History

package connections
import (
//"git.mascherari.press/cwtch/peer/peer"
//"git.mascherari.press/cwtch/protocol"
"github.com/s-rah/go-ricochet"
//"github.com/s-rah/go-ricochet/channels"
"github.com/s-rah/go-ricochet/connection"
//"github.com/s-rah/go-ricochet/identity"
//"github.com/s-rah/go-ricochet/utils"
//"time"
)
type PeerPeerConnection struct {
connection.AutoConnectionHandler
PeerHostname string
state ConnectionState
connection connection.Connection
}
func NewPeerPeerConnection(peerhostname string) *PeerPeerConnection {
ppc := new(PeerPeerConnection)
ppc.PeerHostname = peerhostname
ppc.Init()
return ppc
}
// GetState returns the current connection state
func (ppc *PeerPeerConnection) GetState() ConnectionState {
return ppc.state
}
// Run manages the setup and teardown of a peer->peer connection
func (ppc *PeerPeerConnection) Run() error {
rc, err := goricochet.Open(ppc.PeerHostname)
if err == nil {
rc.TraceLog(true)
ppc.connection = *rc
ppc.state = CONNECTED
}
return err
}