cwtch/app/app.go

48 lines
1.0 KiB
Go
Raw Normal View History

2018-04-30 21:47:21 +00:00
package app
import (
"git.mascherari.press/cwtch/peer"
"log"
2018-04-30 21:47:21 +00:00
)
2018-05-16 21:11:04 +00:00
// Application is a facade over a CwtchPeer that provides some wrapping logic.
2018-04-30 21:47:21 +00:00
type Application struct {
Peer *peer.CwtchPeer
2018-04-30 21:47:21 +00:00
}
2018-05-16 21:11:04 +00:00
// NewProfile creates a new CwtchPeer with a given name.
2018-04-30 21:47:21 +00:00
func (app *Application) NewProfile(name string, filename string) error {
profile := peer.NewCwtchPeer(name)
app.Peer = profile
err := profile.Save(filename)
if err == nil {
go func() {
err := app.Peer.Listen()
if err != nil {
log.Panic(err)
}
}()
}
return err
2018-04-30 21:47:21 +00:00
}
2018-05-16 21:11:04 +00:00
// SetProfile loads an existing profile from the given filename.
2018-04-30 21:47:21 +00:00
func (app *Application) SetProfile(filename string) error {
profile, err := peer.LoadCwtchPeer(filename)
2018-04-30 21:47:21 +00:00
app.Peer = profile
if err == nil {
go func() {
err := app.Peer.Listen()
if err != nil {
log.Panic(err)
}
}()
2018-04-30 21:47:21 +00:00
}
return err
}
2018-05-16 21:11:55 +00:00
// PeerRequest attempts to setup peer relationship with the given onion address.`
2018-04-30 21:47:21 +00:00
func (app *Application) PeerRequest(onion string) {
app.Peer.PeerWithOnion(onion)
}