[GIST Camões](https://gist.github.com/Ca-moes/46bae3fe37093de57842407b398cc5ba)
[Docs com exames](https://docs.google.com/document/d/1dujXD-X7kmJJVEtqc9-sywH-nxgG6UZfnvxZZ2T5L6E/edit#heading=h.918qivrad1p3)
# Exame SDIS
## Exame SDIS 2020/21
### Escolha múltipla
1. According to the "End-to-End Argument", distributed applications on the Internet should always use UDP rather than TCP.
- [ ] True
- [x] False
2. One advantage of multicast algorithms based on spanning trees vs epidemic multicast algorithms is that nodes need not keep multicast messages once they have forwarded them along the tree.
- [x] True
- [ ] False
3. In Java RMI, the only way to get a remote reference, i.e. a reference to a remote object, is to use rmiregistry.
- [ ] True
- [x] False
4. On multicore platforms, pure event.driven designs, i.e. event-driven designs that do not use threads, rarely make sense.
- [x] True
- [ ] False
5. Message authenticity and integrity may be achieved with either a digital signature or a HMAC.
- [x] True
- [ ] False
---
7. The Diffie-Hellman protocol allows two entities to authenticate themselves over a public channel, without sharing any secret.
- [ ] True
- [x] False
8. For fault tolerance, the synchronization model is irrelevant, only the fault model matters
- [ ] True
- [x] False
9. In the presence of network partitions, the Bully algorithm may elect more than one leader
- [x] True
- [ ] False
10. Chords name resolution is efficient because it is transitive.
- [ ] True
- [x] False
11. Physical clock synchronization does **not** require **_a priori_** knowledge of message delays
- [x] True
- [ ] False
---
13. If `a --> b`, i.e. if `a` "happened before" event `b`, the event `a` caused event `b`
- [ ] True
- [x] False
14. The two-phase commit protocol tolerates network partitions, as long as they are eventually repaired.
- [x] True
- [ ] False
15. In the primary-backup protocol, unless the client requests are idempotent, the clients must tag every request with a (unique) identifier.
- [x] True
- [ ] False
16. In the Synod algorithm, the value sent in an ACCEPT request may not be the value decided, even if there are no faults.
- [x] True
- [ ] False
17. View synchronous communication facilitates primary-backup replication mainly because it requires no additional messages to elect a new primary when the previous one fails.
- [ ] True
- [x] False
<br>
### Desenvolvimento
17. Consider the following sentence. **In a service whose operations are not idempotent, the use of TCP rather than UDP does not significantly simplify the implementation, unless we can rule out the failure of the server.** Is it true or false? Justify your answer.
> A menos que o servidor nao falhe nao ha grande vantagem em usar TCP em vez de UDP?
>
> Operações idempotentes (3pts)
> Propriedades TCP
> TCP nao garante sempre que as mensagens sao entregues. Apenas garante isto no contexto de uma conexão.
> Vou deixar aqui um exemplo de uma explicação para cada tópico para ver se tiro algumas dúvidas.
>
> Operações idempotentes são operações cuja ordem não importa, ou seja, independentemente do momento em que a operação seja executada o seu resultado vai ser sempre o mesmo. No caso do exercício, como não são idempotentes é importante que a ordem de chegada das mensagens seja a ordem de envio e que não existam mensagens duplicadas, por isso, UDP pode originar mais problemas.
> Ao utilizar TCP podemos assumir que, caso as mensagems sejam entregues corretamente, chegam por ordem e sem duplicados. Como em TCP existe uma confirmação de que as mensagens chegaram ao destino, existe uma garantia de que as mensagens são corretamente enviadas, ou seja, chegam por ordem e sem duplicados. No caso do exercício, como se pode excluir erros do servidor, é mais fácil implementar TCP pois, ao contrário de UDP, o único problema que é necessário corrigir é uma falha na conexão com o servidor.
> Assim, a afirmação da pergunta é verdadeira pois é mais simples implementar o serviço com base em TCP do que UDP, desde que possamos assumir que o não irão existir falhas por parte do servidor.
>
>
> Ele não disse nada na correção, mas eu explicaria também como é que funciona o UDP para comparar melhor com o TCP
> Não sei bem o que dizer no último tópico, mas foi aquele que ninguém meteu.
>
> Se algum de vocês estiver a pensar, "eu não conseguia escrever tanto", fica uma dica extra. 1 frase para explicar 1 ponto. 1 frase para explicar a mesma coisa por outras palavras. 1 frase para encaixar no exercício. 1 parágrafo final a dizer "por causa do que foi dito antes a minha reposta é tal".
18. Consider the following sentence. **DNS is scalable mostly because it uses UDP for sending queries and their responses.** Is it true or false? Justify your answer.
> Falso.
> DNS é scalable pela sua estrutura hierarquica.
> DNS pode usar UDP ou TCP (normalmente UDP)
> O uso de UDP em vez de TCP tem vantagens porque o overhead da conexão será afetado, melhorando o desempenho ao usar UDP.
19. Concurrency is a criticial aspect in the design of distributed services and a common way to achieve it is to use multiple threads. Consider the first project and the **backup subprotocol without enhancements**.
1. Justify the advantages of using multiple threads in this case.
2. Outline a **concurrency design** for the **non initiator peers** to handle a PUTCHUNK message, including its reception, the writing of the chunk to the disk, and the sending of the STORED message. Note that we are interested essentially in the description of the threads involved, the tasks they do, whether they are permanent threads, threads created dynamically, or threads of a thread pool, and, if there are multiple threads involved, how they synchronize/communicate among them. Justify your choices. Note that this design may be different from the one you have implemented in your first assignment.
3. **Hint**: Remember that STORED messages are sent only after a random delay.
```
Consider the first project and the backup of a file with multiple chunks.
1) Justify the advantages of using multiple threads in this case.
2) Outline a concurrency design for the non initiator peers to handle the PUTCHUNK messages
- how many threads and how are they created?
- what does each thread do?
- if you are using more than one thread how do the multiple threads synchronize and communicate among them?
```
> Vou deixar a resposta por tópicos 👏👏
>
> By using multiple threads our program will not be waiting for other parts of the program to finish.
> This lets the service scale better and lets the backup, or other protocols, to be executing at the same time.
>
> Non initiator peers have a permanent thread running waiting to receive a message.
> When a message is received, we create a thread from a thread-pool to handle the message. (thread-pool because a lot of messages can be received at the same time and their purpose is similar (handling a message)).
> When writing the chunk to disk we create a thread dynamically to handle the store in order to make it asynchronous. We use the AsynchronousFileChannel java class to handle the writing of the chunk in an asycnhronous way.
> After writing to disk we send the STORED message in a new thread created only for this.
> Since we're using multiple threads, for them to comunicate we either pass the info as parameters when creating the thread (message to the message handler thread), or we use the java.utils.concurrent and java.nio classes, like a ConcurrentHashMap, to have no problems sharing info between threads.
>
> Acho que o mais importante eram estes tópicos, sempre com um bocado de palha pelo meio.
## Exame SDIS 2017/18
1 - In some cases, one allows more than one leader (Slides election)
2 - Public key certificates rely on the knowledge of the public key of certificate authorities (Não vi nada nos slides, fui ver à net)
3 - false
4 - true
5 - true (leases can be used with sychronized rate)
6 - all true
7 - false (Slides fault tolerance)
8 - true (ver documentação java sobre SSLSocket)
9 - pode-se usar clocks em vez de timestamp
10 - false (?)
11.1 - Message 1 -> Alice sends a message to KDC saying she wants to talk to Bob
Message 2 -> The KDC returns a message contained a shared secret key (K A,B)
encrypted with the private key K A,KDC that Alice shares with KDC. The same thing happens for Bob
12 - all statements are true (Coelho)
13 - true (xavier disse que dois servidores de rmi não podem ter o mesmo nome)
14 - One hop protocol (sem certezas)
15 - true
16-
## Exame SDIS 2016/17
1 - A proccess may not know the current global state. (Slide Introduction to Distributed Systems: System global state is unknown (relativity)).
2 - The structure of the code... (Está no exame de 2016)
3 - All statements are true. (Introduction to security slides: Are used to check data integrity. By "adding" a key to the message/data hash functions can be used to authenticate. Non reversible, i.e. (One-way) (Assumi que este último ponto garante confidencialidade))
4 - ...vector-timestamp / Vector-timestamps (Xavier: eu estou indeciso entre estas 2 mas apostava na alínea d) ).
## Exame SDIS 2015/16
## Exame SDIS 2014/15
## Exame SDIS 2013/14
#### 1
a - falso
b - falso (Não se consegue usar TCP em multicast?)
c - falso (Os sistemas devem ser distintos)
d - verdadeiro (Não tenho certeza porque não percebi bem a segunda parte da expressão)
e - MapReduce?
f - Napster?
g - TTL?
h -
## Exame SDIS 2012/13