Skeleton of core API
This commit is contained in:
commit
0508f0b5e3
|
@ -0,0 +1,7 @@
|
|||
package core
|
||||
|
||||
type ChatChannel struct {
|
||||
}
|
||||
|
||||
func (chat *ChatChannel) SendMessage(text string) {
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
}
|
||||
|
||||
func LoadConfig(configPath string) (*Config, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package core
|
||||
|
||||
type ContactStatus int
|
||||
|
||||
const (
|
||||
ContactOnline ContactStatus = iota
|
||||
ContactOffline
|
||||
ContactRequestPending
|
||||
ContactRequestRejected
|
||||
ContactOutdated
|
||||
)
|
||||
|
||||
type Contact struct {
|
||||
InternalId int
|
||||
|
||||
Name string
|
||||
Address string
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type ContactList struct {
|
||||
contacts map[int]*Contact
|
||||
outboundRequests map[int]*OutboundContactRequest
|
||||
inboundRequests map[int]*InboundContactRequest
|
||||
}
|
||||
|
||||
func (this *ContactList) Contacts() []*Contact {
|
||||
re := make([]*Contact, 0, len(this.contacts))
|
||||
for _, contact := range this.contacts {
|
||||
re = append(re, contact)
|
||||
}
|
||||
return re
|
||||
}
|
||||
|
||||
func (this *ContactList) OutboundRequests() []*OutboundContactRequest {
|
||||
re := make([]*OutboundContactRequest, 0, len(this.outboundRequests))
|
||||
for _, request := range this.outboundRequests {
|
||||
re = append(re, request)
|
||||
}
|
||||
return re
|
||||
}
|
||||
|
||||
func (this *ContactList) InboundRequests() []*InboundContactRequest {
|
||||
re := make([]*InboundContactRequest, 0, len(this.inboundRequests))
|
||||
for _, request := range this.inboundRequests {
|
||||
re = append(re, request)
|
||||
}
|
||||
return re
|
||||
}
|
||||
|
||||
func (this *ContactList) ContactById(id int) *Contact {
|
||||
return this.contacts[id]
|
||||
}
|
||||
|
||||
func (this *ContactList) ContactByAddress(address string) *Contact {
|
||||
for _, contact := range this.contacts {
|
||||
if contact.Address == address {
|
||||
return contact
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (contacts *ContactList) AddContact(address string, name string) (*Contact, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
}
|
||||
|
||||
func (contacts *ContactList) RemoveContactById(id int) error {
|
||||
return errors.New("Not implemented")
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package core
|
||||
|
||||
type Identity struct {
|
||||
internalId int
|
||||
|
||||
name string
|
||||
address string
|
||||
|
||||
contactList *ContactList
|
||||
}
|
||||
|
||||
func CreateIdentity(id int, name string) *Identity {
|
||||
me := &Identity{
|
||||
internalId: id,
|
||||
name: name,
|
||||
contactList: &ContactList{},
|
||||
}
|
||||
return me
|
||||
}
|
||||
|
||||
func (me *Identity) InternalId() int {
|
||||
return me.internalId
|
||||
}
|
||||
|
||||
func (me *Identity) Name() string {
|
||||
return me.name
|
||||
}
|
||||
|
||||
func (me *Identity) Address() string {
|
||||
return me.address
|
||||
}
|
||||
|
||||
func (me *Identity) ContactList() *ContactList {
|
||||
return me.contactList
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type InboundContactRequest struct {
|
||||
Name string
|
||||
Address string
|
||||
Received time.Time
|
||||
}
|
||||
|
||||
func (request *InboundContactRequest) Accept() (*Contact, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
}
|
||||
|
||||
func (request *InboundContactRequest) Reject(message string) error {
|
||||
return errors.New("Not implemented")
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package core
|
||||
|
||||
type NetworkStatus int
|
||||
|
||||
const (
|
||||
NetworkUnavailable NetworkStatus = iota
|
||||
NetworkError
|
||||
NetworkOffline
|
||||
NetworkOnline
|
||||
)
|
||||
|
||||
type Network struct {
|
||||
torConfig *TorConfiguration
|
||||
status NetworkStatus
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package core
|
||||
|
||||
type OutboundContactRequestStatus int
|
||||
|
||||
const (
|
||||
RequestPending OutboundContactRequestStatus = iota
|
||||
RequestAcknowledged
|
||||
RequestAccepted
|
||||
RequestRejected
|
||||
RequestError
|
||||
)
|
||||
|
||||
type OutboundContactRequest struct {
|
||||
Contact
|
||||
|
||||
MyName string
|
||||
Message string
|
||||
|
||||
Status OutboundContactRequestStatus
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package core
|
||||
|
||||
type Ricochet struct {
|
||||
Network *Network
|
||||
Identity *Identity
|
||||
Config *Config
|
||||
}
|
||||
|
||||
func Initialize(configPath string) (*Ricochet, error) {
|
||||
cfg, err := LoadConfig(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ricochet := &Ricochet{
|
||||
Config: cfg,
|
||||
}
|
||||
|
||||
return ricochet, nil
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package core
|
||||
|
||||
type TorConfiguration struct {
|
||||
}
|
Loading…
Reference in New Issue