Skeleton of core API

This commit is contained in:
John Brooks 2016-06-30 21:18:55 -06:00
commit 0508f0b5e3
10 changed files with 207 additions and 0 deletions

7
core/chatchannel.go Normal file
View File

@ -0,0 +1,7 @@
package core
type ChatChannel struct {
}
func (chat *ChatChannel) SendMessage(text string) {
}

12
core/config.go Normal file
View File

@ -0,0 +1,12 @@
package core
import (
"errors"
)
type Config struct {
}
func LoadConfig(configPath string) (*Config, error) {
return nil, errors.New("Not implemented")
}

18
core/contact.go Normal file
View File

@ -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
}

56
core/contactlist.go Normal file
View File

@ -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")
}

35
core/identity.go Normal file
View File

@ -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
}

View File

@ -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")
}

15
core/network.go Normal file
View File

@ -0,0 +1,15 @@
package core
type NetworkStatus int
const (
NetworkUnavailable NetworkStatus = iota
NetworkError
NetworkOffline
NetworkOnline
)
type Network struct {
torConfig *TorConfiguration
status NetworkStatus
}

View File

@ -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
}

20
core/ricochet.go Normal file
View File

@ -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
}

4
core/torconfiguration.go Normal file
View File

@ -0,0 +1,4 @@
package core
type TorConfiguration struct {
}