Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into dir-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
mjtognetti committed Nov 22, 2019
2 parents 1aa38b1 + e4c6115 commit cb070cb
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/MessageRouter.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/MessageRouter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/MessageRouter.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/Network.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/Network.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/PeerConnection.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/MessageRouter.ts
Expand Up @@ -33,14 +33,14 @@ export default class MessageRouter<Msg> {

sendToPeer(peer: NetworkPeer, msg: Msg): void {
const bus = this.getBus(peer)
bus.send(msg)
bus?.send(msg)
}

getBus(peer: NetworkPeer): MessageBus<Msg> {
if (!peer.connection) throw new Error('peer has no connection')
getBus(peer: NetworkPeer): MessageBus<Msg> | undefined {
if (!peer.connection) return

return getOrCreate(this.buses, peer.connection, (conn) => {
const bus = new MessageBus<Msg>(conn.openChannel(this.channelName))
const bus = conn.openBus<Msg>(this.channelName)

bus.receiveQ.subscribe((msg) => {
this.inboxQ.push({
Expand Down
4 changes: 2 additions & 2 deletions src/Network.ts
Expand Up @@ -144,10 +144,10 @@ export default class Network {

networkBus.close()

if (firstMsg.type !== 'Info') throw new Error('First message must be Info.')
if (firstMsg.type !== 'Info') return conn.close('error')

const { peerId } = firstMsg
if (peerId === this.selfId) throw new Error('Connected to self.')
if (peerId === this.selfId) return conn.close('self-connection')

this.getOrCreatePeer(peerId).addConnection(conn)
}
Expand Down
2 changes: 1 addition & 1 deletion src/PeerConnection.ts
Expand Up @@ -11,7 +11,7 @@ import Heartbeat from './Heartbeat'
const log = Debug('PeerConnection')
const VERSION_PREFIX = Buffer.from('hypermerge.v2')

type CloseReason = 'outdated' | 'timeout' | 'error' | 'shutdown' | 'unknown'
type CloseReason = 'outdated' | 'timeout' | 'error' | 'shutdown' | 'self-connection' | 'unknown'

export interface SocketInfo {
type: string
Expand Down

0 comments on commit cb070cb

Please sign in to comment.