commit 0508f0b5e37330845487f16eb289eb66865855f4 Author: John Brooks Date: Thu Jun 30 21:18:55 2016 -0600 Skeleton of core API diff --git a/core/chatchannel.go b/core/chatchannel.go new file mode 100644 index 0000000..3d36d68 --- /dev/null +++ b/core/chatchannel.go @@ -0,0 +1,7 @@ +package core + +type ChatChannel struct { +} + +func (chat *ChatChannel) SendMessage(text string) { +} diff --git a/core/config.go b/core/config.go new file mode 100644 index 0000000..aa9a84e --- /dev/null +++ b/core/config.go @@ -0,0 +1,12 @@ +package core + +import ( + "errors" +) + +type Config struct { +} + +func LoadConfig(configPath string) (*Config, error) { + return nil, errors.New("Not implemented") +} diff --git a/core/contact.go b/core/contact.go new file mode 100644 index 0000000..fc7b207 --- /dev/null +++ b/core/contact.go @@ -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 +} diff --git a/core/contactlist.go b/core/contactlist.go new file mode 100644 index 0000000..f983c3a --- /dev/null +++ b/core/contactlist.go @@ -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") +} diff --git a/core/identity.go b/core/identity.go new file mode 100644 index 0000000..2e87a20 --- /dev/null +++ b/core/identity.go @@ -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 +} diff --git a/core/inboundcontactrequest.go b/core/inboundcontactrequest.go new file mode 100644 index 0000000..af13a23 --- /dev/null +++ b/core/inboundcontactrequest.go @@ -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") +} diff --git a/core/network.go b/core/network.go new file mode 100644 index 0000000..b5eec6e --- /dev/null +++ b/core/network.go @@ -0,0 +1,15 @@ +package core + +type NetworkStatus int + +const ( + NetworkUnavailable NetworkStatus = iota + NetworkError + NetworkOffline + NetworkOnline +) + +type Network struct { + torConfig *TorConfiguration + status NetworkStatus +} diff --git a/core/outboundcontactrequest.go b/core/outboundcontactrequest.go new file mode 100644 index 0000000..19da38d --- /dev/null +++ b/core/outboundcontactrequest.go @@ -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 +} diff --git a/core/ricochet.go b/core/ricochet.go new file mode 100644 index 0000000..c6f08b0 --- /dev/null +++ b/core/ricochet.go @@ -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 +} diff --git a/core/torconfiguration.go b/core/torconfiguration.go new file mode 100644 index 0000000..3ede44e --- /dev/null +++ b/core/torconfiguration.go @@ -0,0 +1,4 @@ +package core + +type TorConfiguration struct { +}