forked from cwtch.im/cwtch
Updating Comments
This commit is contained in:
parent
5d7bdce118
commit
086e964514
|
@ -16,7 +16,7 @@ type CwtchPeerFetchChannel struct {
|
|||
Handler CwtchPeerFetchChannelHandler
|
||||
}
|
||||
|
||||
// CwtchPeerFetchChannelHandlersould be implemented by peers to receive new messages.
|
||||
// CwtchPeerFetchChannelHandler should be implemented by peers to receive new messages.
|
||||
type CwtchPeerFetchChannelHandler interface {
|
||||
HandleGroupMessage(*protocol.GroupMessage)
|
||||
}
|
||||
|
|
|
@ -9,24 +9,18 @@ import (
|
|||
"github.com/s-rah/go-ricochet/wire/control"
|
||||
)
|
||||
|
||||
// CwtchPeerListenChannel implements the ChannelHandler interface for a channel of
|
||||
// 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.
|
||||
// CwtchPeerListenChannel is the peer implementation of im.cwtch.server.listen
|
||||
type CwtchPeerListenChannel struct {
|
||||
channel *channels.Channel
|
||||
Handler CwtchPeerSendChannelHandler
|
||||
}
|
||||
|
||||
// CwtchChannelHandler is implemented by an application type to receive
|
||||
// events from a CwtchChannel.
|
||||
// CwtchPeerSendChannelHandler is implemented by peers who want to listen to new messages
|
||||
type CwtchPeerSendChannelHandler interface {
|
||||
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 {
|
||||
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 {
|
||||
return true
|
||||
}
|
||||
|
@ -51,31 +45,24 @@ func (cc *CwtchPeerListenChannel) Bidirectional() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// RequiresAuthentication - Cwtch channels require hidden service auth
|
||||
// RequiresAuthentication - Cwtch channels require no auth channels
|
||||
func (cc *CwtchPeerListenChannel) RequiresAuthentication() string {
|
||||
return "none"
|
||||
}
|
||||
|
||||
// OpenInbound is the first method called for an inbound channel request.
|
||||
// If an error is returned, the channel is rejected. If a RawMessage is
|
||||
// returned, it will be sent as the ChannelResult message.
|
||||
// OpenInbound - peers should never respond to open inbound requests from servers
|
||||
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")
|
||||
}
|
||||
|
||||
// OpenOutbound is the first method called for an outbound channel request.
|
||||
// If an error is returned, the channel is not opened. If a RawMessage is
|
||||
// returned, it will be sent as the OpenChannel message.
|
||||
// OpenOutbound sets up a new server listen channel
|
||||
func (cplc *CwtchPeerListenChannel) OpenOutbound(channel *channels.Channel) ([]byte, error) {
|
||||
cplc.channel = channel
|
||||
messageBuilder := new(utils.MessageBuilder)
|
||||
return messageBuilder.OpenChannel(channel.ID, cplc.Type()), nil
|
||||
}
|
||||
|
||||
// OpenOutboundResult is called when a response is received for an
|
||||
// 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.
|
||||
// OpenOutboundResult confirms a previous open channel request
|
||||
func (cplc *CwtchPeerListenChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult) {
|
||||
if err == nil {
|
||||
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) {
|
||||
csp := &protocol.CwtchServerPacket{}
|
||||
err := proto.Unmarshal(data, csp)
|
||||
|
|
|
@ -10,19 +10,14 @@ import (
|
|||
"github.com/s-rah/go-ricochet/wire/control"
|
||||
)
|
||||
|
||||
// CwtchChannel implements the ChannelHandler interface for a channel of
|
||||
// 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.
|
||||
// CwtchPeerSendChannel is the peer implementation of im.cwtch.server.send
|
||||
type CwtchPeerSendChannel struct {
|
||||
channel *channels.Channel
|
||||
spamGuard spam.SpamGuard
|
||||
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 {
|
||||
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 {
|
||||
return true
|
||||
}
|
||||
|
@ -47,21 +42,17 @@ func (cc *CwtchPeerSendChannel) Bidirectional() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// RequiresAuthentication - Cwtch channels require hidden service auth
|
||||
// RequiresAuthentication - Cwtch channels require no auth
|
||||
func (cc *CwtchPeerSendChannel) RequiresAuthentication() string {
|
||||
return "none"
|
||||
}
|
||||
|
||||
// OpenInbound is the first method called for an inbound channel request.
|
||||
// If an error is returned, the channel is rejected. If a RawMessage is
|
||||
// returned, it will be sent as the ChannelResult message.
|
||||
// OpenInbound should never be called on peers.
|
||||
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")
|
||||
}
|
||||
|
||||
// OpenOutbound is the first method called for an outbound channel request.
|
||||
// If an error is returned, the channel is not opened. If a RawMessage is
|
||||
// returned, it will be sent as the OpenChannel message.
|
||||
// OpenOutbound is used to set up a new send channel and initialize spamguard
|
||||
func (cplc *CwtchPeerSendChannel) OpenOutbound(channel *channels.Channel) ([]byte, error) {
|
||||
cplc.spamGuard.Difficulty = 2
|
||||
cplc.channel = channel
|
||||
|
@ -69,10 +60,7 @@ func (cplc *CwtchPeerSendChannel) OpenOutbound(channel *channels.Channel) ([]byt
|
|||
return messageBuilder.OpenChannel(channel.ID, cplc.Type()), nil
|
||||
}
|
||||
|
||||
// OpenOutboundResult is called when a response is received for an
|
||||
// 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.
|
||||
// OpenOutboundResult confirms the open channel request and sets the spamguard challenge
|
||||
func (cplc *CwtchPeerSendChannel) OpenOutboundResult(err error, crm *Protocol_Data_Control.ChannelResult) {
|
||||
if err == nil {
|
||||
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) {
|
||||
sgsolve := cplc.spamGuard.SolveChallenge(cplc.challenge, gm.GetCiphertext())
|
||||
gm.Spamguard = sgsolve
|
||||
|
@ -95,7 +83,7 @@ func (cplc *CwtchPeerSendChannel) SendGroupMessage(gm *protocol.GroupMessage) {
|
|||
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) {
|
||||
// If we receive a packet on this channel, close the connection
|
||||
cc.channel.CloseChannel()
|
||||
|
|
Loading…
Reference in New Issue