Updating Comments

This commit is contained in:
Sarah Jamie Lewis 2018-03-09 12:49:49 -08:00
parent 5d7bdce118
commit 086e964514
3 changed files with 19 additions and 44 deletions

View File

@ -16,7 +16,7 @@ type CwtchPeerFetchChannel struct {
Handler CwtchPeerFetchChannelHandler Handler CwtchPeerFetchChannelHandler
} }
// CwtchPeerFetchChannelHandlersould be implemented by peers to receive new messages. // CwtchPeerFetchChannelHandler should be implemented by peers to receive new messages.
type CwtchPeerFetchChannelHandler interface { type CwtchPeerFetchChannelHandler interface {
HandleGroupMessage(*protocol.GroupMessage) HandleGroupMessage(*protocol.GroupMessage)
} }

View File

@ -9,24 +9,18 @@ import (
"github.com/s-rah/go-ricochet/wire/control" "github.com/s-rah/go-ricochet/wire/control"
) )
// CwtchPeerListenChannel implements the ChannelHandler interface for a channel of // CwtchPeerListenChannel is the peer implementation of im.cwtch.server.listen
// type "im.ricochet.Cwtch". The channel may be inbound or outbound.
//
// CwtchChannel implements protocol-level sanity and state validation, but
// does not handle or acknowledge Cwtch messages. The application must provide
// a CwtchChannelHandler implementation to handle Cwtch events.
type CwtchPeerListenChannel struct { type CwtchPeerListenChannel struct {
channel *channels.Channel channel *channels.Channel
Handler CwtchPeerSendChannelHandler Handler CwtchPeerSendChannelHandler
} }
// CwtchChannelHandler is implemented by an application type to receive // CwtchPeerSendChannelHandler is implemented by peers who want to listen to new messages
// events from a CwtchChannel.
type CwtchPeerSendChannelHandler interface { type CwtchPeerSendChannelHandler interface {
HandleGroupMessage(*protocol.GroupMessage) HandleGroupMessage(*protocol.GroupMessage)
} }
// Type returns the type string for this channel, e.g. "im.ricochet.Cwtch". // Type returns the type string for this channel, e.g. "im.ricochet.server.listen".
func (cc *CwtchPeerListenChannel) Type() string { func (cc *CwtchPeerListenChannel) Type() string {
return "im.cwtch.server.listen" return "im.cwtch.server.listen"
} }
@ -36,7 +30,7 @@ func (cc *CwtchPeerListenChannel) Closed(err error) {
} }
// OnlyClientCanOpen - for Cwtch channels any side can open // OnlyClientCanOpen - for Cwtch server channels can only be opened by peers
func (cc *CwtchPeerListenChannel) OnlyClientCanOpen() bool { func (cc *CwtchPeerListenChannel) OnlyClientCanOpen() bool {
return true return true
} }
@ -51,31 +45,24 @@ func (cc *CwtchPeerListenChannel) Bidirectional() bool {
return false return false
} }
// RequiresAuthentication - Cwtch channels require hidden service auth // RequiresAuthentication - Cwtch channels require no auth channels
func (cc *CwtchPeerListenChannel) RequiresAuthentication() string { func (cc *CwtchPeerListenChannel) RequiresAuthentication() string {
return "none" return "none"
} }
// OpenInbound is the first method called for an inbound channel request. // OpenInbound - peers should never respond to open inbound requests from servers
// If an error is returned, the channel is rejected. If a RawMessage is
// returned, it will be sent as the ChannelResult message.
func (cc *CwtchPeerListenChannel) OpenInbound(channel *channels.Channel, raw *Protocol_Data_Control.OpenChannel) ([]byte, error) { func (cc *CwtchPeerListenChannel) OpenInbound(channel *channels.Channel, raw *Protocol_Data_Control.OpenChannel) ([]byte, error) {
return nil, errors.New("client does not receive inbound listen channels") return nil, errors.New("client does not receive inbound listen channels")
} }
// OpenOutbound is the first method called for an outbound channel request. // OpenOutbound sets up a new server listen channel
// If an error is returned, the channel is not opened. If a RawMessage is
// returned, it will be sent as the OpenChannel message.
func (cplc *CwtchPeerListenChannel) OpenOutbound(channel *channels.Channel) ([]byte, error) { func (cplc *CwtchPeerListenChannel) OpenOutbound(channel *channels.Channel) ([]byte, error) {
cplc.channel = channel cplc.channel = channel
messageBuilder := new(utils.MessageBuilder) messageBuilder := new(utils.MessageBuilder)
return messageBuilder.OpenChannel(channel.ID, cplc.Type()), nil return messageBuilder.OpenChannel(channel.ID, cplc.Type()), nil
} }
// OpenOutboundResult is called when a response is received for an // OpenOutboundResult confirms a previous open channel request
// outbound OpenChannel request. If `err` is non-nil, the channel was
// rejected and Closed will be called immediately afterwards. `raw`
// contains the raw protocol message including any extension data.
func (cplc *CwtchPeerListenChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult) { func (cplc *CwtchPeerListenChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult) {
if err == nil { if err == nil {
if crm.GetOpened() { if crm.GetOpened() {
@ -84,7 +71,7 @@ func (cplc *CwtchPeerListenChannel) OpenOutboundResult(err error, crm *Protocol_
} }
} }
// Packet is called for each raw packet received on this channel. // Packet is called for each server packet received on this channel.
func (cplc *CwtchPeerListenChannel) Packet(data []byte) { func (cplc *CwtchPeerListenChannel) Packet(data []byte) {
csp := &protocol.CwtchServerPacket{} csp := &protocol.CwtchServerPacket{}
err := proto.Unmarshal(data, csp) err := proto.Unmarshal(data, csp)

View File

@ -10,19 +10,14 @@ import (
"github.com/s-rah/go-ricochet/wire/control" "github.com/s-rah/go-ricochet/wire/control"
) )
// CwtchChannel implements the ChannelHandler interface for a channel of // CwtchPeerSendChannel is the peer implementation of im.cwtch.server.send
// type "im.ricochet.Cwtch". The channel may be inbound or outbound.
//
// CwtchChannel implements protocol-level sanity and state validation, but
// does not handle or acknowledge Cwtch messages. The application must provide
// a CwtchChannelHandler implementation to handle Cwtch events.
type CwtchPeerSendChannel struct { type CwtchPeerSendChannel struct {
channel *channels.Channel channel *channels.Channel
spamGuard spam.SpamGuard spamGuard spam.SpamGuard
challenge []byte challenge []byte
} }
// Type returns the type string for this channel, e.g. "im.ricochet.Cwtch". // Type returns the type string for this channel, e.g. "im.ricochet.server.send".
func (cc *CwtchPeerSendChannel) Type() string { func (cc *CwtchPeerSendChannel) Type() string {
return "im.cwtch.server.send" return "im.cwtch.server.send"
} }
@ -32,7 +27,7 @@ func (cc *CwtchPeerSendChannel) Closed(err error) {
} }
// OnlyClientCanOpen - for Cwtch channels any side can open // OnlyClientCanOpen - for Cwtch server channels only peers may open.
func (cc *CwtchPeerSendChannel) OnlyClientCanOpen() bool { func (cc *CwtchPeerSendChannel) OnlyClientCanOpen() bool {
return true return true
} }
@ -47,21 +42,17 @@ func (cc *CwtchPeerSendChannel) Bidirectional() bool {
return false return false
} }
// RequiresAuthentication - Cwtch channels require hidden service auth // RequiresAuthentication - Cwtch channels require no auth
func (cc *CwtchPeerSendChannel) RequiresAuthentication() string { func (cc *CwtchPeerSendChannel) RequiresAuthentication() string {
return "none" return "none"
} }
// OpenInbound is the first method called for an inbound channel request. // OpenInbound should never be called on peers.
// If an error is returned, the channel is rejected. If a RawMessage is
// returned, it will be sent as the ChannelResult message.
func (cc *CwtchPeerSendChannel) OpenInbound(channel *channels.Channel, raw *Protocol_Data_Control.OpenChannel) ([]byte, error) { func (cc *CwtchPeerSendChannel) OpenInbound(channel *channels.Channel, raw *Protocol_Data_Control.OpenChannel) ([]byte, error) {
return nil, errors.New("client does not receive inbound listen channels") return nil, errors.New("client does not receive inbound listen channels")
} }
// OpenOutbound is the first method called for an outbound channel request. // OpenOutbound is used to set up a new send channel and initialize spamguard
// If an error is returned, the channel is not opened. If a RawMessage is
// returned, it will be sent as the OpenChannel message.
func (cplc *CwtchPeerSendChannel) OpenOutbound(channel *channels.Channel) ([]byte, error) { func (cplc *CwtchPeerSendChannel) OpenOutbound(channel *channels.Channel) ([]byte, error) {
cplc.spamGuard.Difficulty = 2 cplc.spamGuard.Difficulty = 2
cplc.channel = channel cplc.channel = channel
@ -69,10 +60,7 @@ func (cplc *CwtchPeerSendChannel) OpenOutbound(channel *channels.Channel) ([]byt
return messageBuilder.OpenChannel(channel.ID, cplc.Type()), nil return messageBuilder.OpenChannel(channel.ID, cplc.Type()), nil
} }
// OpenOutboundResult is called when a response is received for an // OpenOutboundResult confirms the open channel request and sets the spamguard challenge
// outbound OpenChannel request. If `err` is non-nil, the channel was
// rejected and Closed will be called immediately afterwards. `raw`
// contains the raw protocol message including any extension data.
func (cplc *CwtchPeerSendChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult) { func (cplc *CwtchPeerSendChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult) {
if err == nil { if err == nil {
if crm.GetOpened() { if crm.GetOpened() {
@ -84,7 +72,7 @@ func (cplc *CwtchPeerSendChannel) OpenOutboundResult(err error, crm *Protocol_Da
} }
// SendGroupMessage // SendGroupMessage performs the spamguard proof of work and sends a message.
func (cplc *CwtchPeerSendChannel) SendGroupMessage(gm *protocol.GroupMessage) { func (cplc *CwtchPeerSendChannel) SendGroupMessage(gm *protocol.GroupMessage) {
sgsolve := cplc.spamGuard.SolveChallenge(cplc.challenge, gm.GetCiphertext()) sgsolve := cplc.spamGuard.SolveChallenge(cplc.challenge, gm.GetCiphertext())
gm.Spamguard = sgsolve gm.Spamguard = sgsolve
@ -95,7 +83,7 @@ func (cplc *CwtchPeerSendChannel) SendGroupMessage(gm *protocol.GroupMessage) {
cplc.channel.SendMessage(packet) cplc.channel.SendMessage(packet)
} }
// Packet is called for each raw packet received on this channel. // Packet should never be called
func (cc *CwtchPeerSendChannel) Packet(data []byte) { func (cc *CwtchPeerSendChannel) Packet(data []byte) {
// If we receive a packet on this channel, close the connection // If we receive a packet on this channel, close the connection
cc.channel.CloseChannel() cc.channel.CloseChannel()